pytorch小记(一):pytorch矩阵乘法:torch.matmul(x, y)/ x @ y
代码
x = torch.tensor([[1,2,3,4], [5,6,7,8]])
y = torch.tensor([2, 3, 1, 0]) # y.shape == (4)
print(torch.matmul(x, y))
print(x @ y)
>>>
tensor([11, 35])
tensor([11, 35])
x = torch.tensor([[1,2,3,4], [5,6,7,8]])
y = torch.tensor([2, 3, 1, 0]) # y.shape == (4)
y = y.view(4,1) # y.shape == (4, 1)
'''
tensor([[2],
[3],
[1],
[0]])
'''
print(torch.matmul(x, y))
print(x @ y)
>>>
tensor([[11],
[35]])
tensor([[11],
<