PyTorch中的张量数学运算

  1. 加减乘除
    torch.add(input, alpha=1, other, out=None)
    torch.addcdiv(tensor, value=1, tensor1, tensor2, out=None)
    torch.addcmul(tensor, value=1, tensor1, tensor2, out=None)
    torch.sub(input, other, out=None)
    torch.mul(input, other, out=None)
    torch.div(input, other, out=None)

  2. 对数,指数,幂函数
    torch.log(input, out=None) ——以e为底
    torch.log10(input, out=None)
    torch.log2(input, out=None)
    torch.exp(input, out=None)
    torch.pow(input, exponent, out=None)

  3. 三角函数
    torch.acos(input, out=None)
    torch.cosh(input, out=None)
    torch.cos(input, out=None)
    torch.asin(input, out=None)
    torch.sinh(input, out=None)
    torch.sin(input, out=None)
    torch.atan(input, out=None)
    torch.tanh(input, out=None)
    torch.tan(input, out=None)
    torch.atan2(input, other, out=None)

  4. 绝对值
    torch.abs(input, out=None)

torch.add()

torch.add(input, 
          alpha=1, 
          other, 
          out=None)

功能: 逐元素计算 input+alpha×other,因为深度学习中经常用到先乘后加的操作,所以增加了此功能,可以使代码更加整洁

  • input: 第一个张量
  • alpha: 乘项因子
  • other: 第二个张量

torch.addcdiv()

torch.addcdiv(tensor, 
              value=1, 
              tensor1, 
              tensor2, 
              out=None) 

功能: 逐元素计算 o u t = i n p u t + v a l u e × t e n s o r 1 t e n s o r 2 out = input + value \times \frac{tensor1}{tensor2} out=input+value×tensor2tensor1,优化过程中常用

torch.addcmul()

torch.addcmul(tensor, 
              value=1, 
              tensor1, 
              tensor2, 
              out=None) 

功能: 逐元素计算 o u t = i n p u t + v a l u e × t e n s o r 1 × t e n s o r 2 out = input + value \times tensor1 \times tensor2 out=input+value×tensor1×tensor2,优化过程中常用

torch.atan2()

torch.atan2(input, 
            other, 
            out=None)

功能: Element-wise arctangent of i n p u t i o t h e r i \frac{input_i}{other_i} otheriinputi with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector ( o t h e r i , i n p u t i other_i, input_i otheri,inputi) and vector (1, 0).
注意: o t h e r i other_i otheri, the second parameter, is the x-coordinate, while i n p u t i input_i inputi, the first parameter, is the y-coordinate.

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值