I am confused between the multiplication between two tensors using * and matmul. Below is my code
import torch
torch.manual_seed(7)
features = torch.randn((2, 5))
weights = torch.randn_like(features)
here, i want to multiply weights and features. so, one way to do it is as follows
print(torch.sum(features * weights))
Output:
tensor(-2.6123)
Another way to do is using matmul
print(torch.mm(features,weights.view((5,2))))
but, here output is
tensor([[ 2.8089, 4.6439],
[-2.3988, -1.9238]])
What i don't understand here is that why matmul and usual multiplication are giving different outputs, when both are same. Am i doing anything wrong here?
Edit: When, i am using feature of shape (1,5) both * and matmul outputs are same.
but, its not the same when the shape is (2,5).