Matrices multiplication: inconsistent tensor size

Using PyTorch 0.1.12 and trying to multiply two matrices in the following sizes: [1,49,1] and [1,49,256], but when I do I get the error:

RuntimeError: inconsistent tensor size

I tried using .expand_as for both matrices but it didn’t work.
(I know that it works on newer versions)

I’ve tested it in my 0.1.12 environment and it should work like you tried it:

a = torch.randn(1, 49, 1)
b = torch.randn(1, 49, 256)
c = a.expand_as(b) * b
1 Like

Yeah, you’re right. For some reason I thought it didn’t work, thanks!