Shaz:

Not sure why this is happening as matrix sizes are same i.e. 784*10


You could have to make sure that the inner matrix sizes are equal:
x = torch.randn(784, 10)
y = torch.randn(10, 784)
out = torch.matmul(x, y)
print(out.shape)
> torch.Size([784, 784])