Pytorch的乘法

a = torch.tensor([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
b = torch.tensor([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
c = a * b
d = torch.mm(a, b)
print(a)
print(b)
print(c)
print(d)

元素对应相乘:直接用*就可以,也可以用 torch.mul(a, b) 

矩阵相乘:torch.mm(a,b)此方法只适用于2维矩阵 torch.matmul(a, b)  推荐使用此方法

一维张量的点乘:torch.dot(a,b)是对两个为1D张量进行点积运算

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章