数学运算与统计属性
2021-11-1
| 2023-8-6
0  |  阅读时长 0 分钟
type
status
date
slug
summary
tags
category
icon
password
Property

Basic

a + b ——torch.add()
a - b ——torch.sub()
a * b ——torch.mul()
a / b ——torch.div()
notion image
 

矩阵相乘

torch.mm:只适用于2D的矩阵相乘
torch.matmul推荐使用
@ 与matmul效果相同
notion image
 
 
 
 

power/sqrt

 
notion image
 

exp/log

exp函数:求自然指数
log函数:求log(默认以e为底)
 
notion image
 

Approximation

floor()向下取整
ceil()向上取整
trunc()取整数部分
frac()取小数部分
round()四舍五入
% 取余
notion image
 

Compare

notion image
 

Clamp

限制矩阵中的最大值与最小值
notion image
 
 
 

Norm范数

范数1:所有元素的绝对值的求和
范数2:所有元素的绝对值的平方和的开方
notion image
 
 
 

Mean Sum Min Max Prod

 

Argmin Argmax

返回的是索引,如果不指定维度,会把所有数据平化返回index
notion image
 
 

Dim,Keepdin

dim参数:指定操作的相应位置在哪维
使用keepdim会将值对应的index全部返回
notion image
 

Top-k or K-th

topk函数与max其实是一样的,只不过topk返回的是前几大的数据
kthvalue函数:返回第几小的元素
notion image

Where

torch.where(condition, x, y):
condition:判断条件 x:若满足条件,则取x中元素 y:若不满足条件,则取y中元素
notion image
 

Gather

notion image
 
 
  • PyTorch
  • 合并与分割线性代数与自动求导
    目录