Hello Elidor!



 Elidor:

I have two 2D tensors of shape:
y = torch.Size([50, 61])   # (batch_size, max_len)
x = torch.Size([50, 800])  # (batch_size, n_lstm_units)

what I would like to get is a 3D tensor made like this:
z = (50, 61, 800)  # (batch_size, max_len, n_lstm_units)

how can I do?


I’m not sure what you’re asking here.
Please note that your x and y together have 50 * (61 + 800)
elements, while your desired z will have 50 * 61 * 800 elements,
a much larger number.  So you can’t simply populate z with elements
of x and y.
I have no idea if this would be what you want, but you can make a
tensor of the desired shape by taking the batch outer product:
z = torch.bmm (x.unsqueeze (2), y.unsqueeze (1))

(Pytorch does have an outer-product function, torch.ger, torch.outer,
but it only works on vectors, hence the unsqueeze(), above.)
Best.
K. Frank