**
一、加减乘除
**
torch.add / torch.sub / torch.mul / torch.div
分别为矩阵对应元素的加减乘除
与使用符号±*/功能相同
//表示整除
In [1]: import torch
In [2]: a = torch.rand(3,4)
In [3]: b = torch.rand(4)
In [4]: a+b
Out[4]:
tensor([[0.2696, 1.2878, 1.4269, 0.6681],
[0.6802, 1.0790, 1.8201, 0.7958],
[1.0932, 1.6674, 0.9889, 0.8394]])
In [5]: torch.add(a,b)
Out[5]:
tensor([[0.2696, 1.2878, 1.4269, 0.6681],
[0.6802, 1.0790, 1.8201, 0.7958],
[1.0932, 1.6674, 0.9889, 0.8394]])
In [6]: torch.all(torch.eq(a+b,torch.add(a,b)))
Out[6]: tensor(1, dtype=torch.uint8)
In [7]: torch.all(torch.eq(a-b,torch.sub(a,b)))
Out[7]: tensor(1, dtype=torch.uint8)
In [8]: torch.all(torch.eq(a*b,torch.mul(a,b)))
Out[8]: tensor(1, dtype=torch.uint8)
In [9]: torch.all(torch.eq(a/b,torch.div(a,b)))
Out[9]: tensor(