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張量進行點積運算