1. 点乘,对应元素相乘,不求和
import torcha = torch.Tensor([[1,2], [3,4], [5,6]])
b1 = a.mul(a)//
b2=a*a
b1
Out[79]:
tensor([[ 1., 4.],[ 9., 16.],[25., 36.]])
b2
Out[80]:
tensor([[ 1., 4.],[ 9., 16.],[25., 36.]])
以上两种方法都可以表示点乘。
2.矩阵相乘
- 要求:前列=后行;
b2 = a.mm(a.t())
b3= a.matmul(a.t())
得到结果
tensor([[ 5., 11., 17.],[11., 25., 39.],[17., 39., 61.]]
以上两种方法都可以