Multiplying two 3D Pytorch tensors iteratively
I have two 3 dimensional Pytorch tensors, one of dimension (8, 1, 1024) and the other has dimension (8, 59, 77). I wish to multiply these two tnesors.
I know they cannot be multiplied in their current state, so I want to multiply them iteratively and append into a single tensor.
The second tensor can be represented as (8, 59, 1) when we iterate over the 2nd dimension. In this state multiplying it with the first tensor of shape (8, 1, 1024), resulting in a tensor of shape (8, 59, 1024), and finally appending all these 77 outputs into one, resulting in the final shape of (8, 59, 1024, 77).
However I am having issues in it's implementation. Can someone help me here ?

If I didn't mess up the computation, it would be equivalent to:
import torch

x = torch.rand(8, 1, 1024)
y = torch.rand(8, 59, 77)

torch.matmul(
    y.unsqueeze(-1),   # shape = (8, 59, 77, 1)
    x.unsqueeze(1)     # shape = (8, 1, 1, 1024)
).permute(0, 1, 3, 2)  # output shape = (8, 59, 1024, 77)

Note that, in this case, matmul performs a batched matrix multiply.
