I have two matrices:
t1 = torch.randn(4,4)
t2 = torch.randn(4,1)
I can matrix-multiply them like so:
res = torch.matmul(t1, t2)
This results in a 4x1 matrix. I would like to do this multiplication many at once. t1
remains the same, but I want to make t2
of the size [4,10,10]
If I use matmul() directly it gives me the error: RuntimeError: Expected size for first two dimensions of batch2 tensor to be: [4, 4] but got: [4, 10].
How can I do this multiplication so that t1
is multiplied by each [:,r,c]
vector inside t2
?