Concat two tensors of different dimensions I have two tensors. For example -
a = torch.randn((500, 200, 10))
b = torch.randn((500, 5))

I have to concat each of b tensor to all elements of corresponding a tensor i.e., each 200 tensors of a[0] should get concatenated with b[0] - final dimension should be (500, 200, 15).
Without using explicit for loop, how can I achieve this in Pytorch efficiently?
For that, you should repeat b 200 times in the appropriate dimension this way:
c = torch.cat([a, torch.unsqueeze(b, 1).repeat(1, 200, 1)], dim=2)
c.shape

As desired, the shape of the result is torch.Size([500, 200, 15])