张量数学运算

181 阅读1分钟

一、加减乘除

torch.add()

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

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

功能:逐元素计算 input + alpha x other

  • input:第一个张量
  • alpha:乘项因子
  • other:第二个张量
t_0 = torch.randn((3,3))
t_1 = torch.ones_like(t_0)
t_add = torch.add(t_0, 10, t_1)
print(t_0)
print(t_1)
print(t_add)
tensor([[ 0.5992,  0.0114,  1.2617],
        [-1.6506, -1.0280,  1.6977],
        [-0.3148,  1.0361,  0.8660]])
tensor([[1., 1., 1.],
        [1., 1., 1.],
        [1., 1., 1.]])
tensor([[10.5992, 10.0114, 11.2617],
        [ 8.3494,  8.9720, 11.6977],
        [ 9.6852, 11.0361, 10.8660]])

image.png

image.png

torch.add()
torch.addcdiv()
torch.addcmul()
torch.sub()
torch.div()
torch.mul()

二、 对数,指数,幂函数

torch.log(input, out=None)
torch.log10(input, out=None)
torch.log2(input, out=None)
torch.exp(input, out=None)
torch.pow()

三、三角函数

torch.abs(input, out=None)
torch.acos(input,out=None)
torch.cosh(input, out=None)
torch.cos(input, out=None)
torch.asin(input, out=None)
torch.atan(input, out=None)
torch.atan2(input, other, out=None)