1. 张量乘法
1.1 dot product
有张量a和张量b
a = torch.tensor([1,2,3])
b = torch.tensor([2,3,1])
c = torch.dot(a,b) = 11
torch.dot(a,b)对参数的限制:a和b均为1维张量。
1.2 element-wise product
c = torch.multiply(a,b) =
2. 矩阵乘法
2.1 inner product
a = torch.tensor([[1,2,3],[2,3,1]])
b = a.T
c = torch.matmul(a,b) =
2.2 element-wise product
a = torch.tensor([[1,2,3],[2,3,1]])
b = torch.tensor([[1,2,2],[3,2,1]])
c = torch.multiply(a,b) 或者 c= torch.mul(a,b)
综上,我们可以发现,张量的点积和矩阵的内积其实是一个道理,同理,张量和矩阵的对应位置元素乘积也是一个道理,我们称之为Hadamard product。
3. torch.concat()
对张量或矩阵沿同一维度进行拼接
a = torch.tensor([1,2,3])
b = torch.tensor([2,3,1])
c= torch.concat([a,b],dim=0) =
d = torch.concat([a,b],dim=1) =
a = torch.tensor([[1,2,3],[2,1,3]])
b = torch.tensor([[2,3,1],[3,2,1]])
c = torch.concat([a,b],dim=0) =
c = torch.concat([a,b],dim=1) =
4.torch.stack()
在新的维度上进行拼接
c = torch.stack([a,b],0),得到2*2*3的矩阵。