Let’s say I have a list of tensors ([A , B , C ] where each tensor of is of shape [batch_size X 1024].

I want to merge all the tensors into a single tensor in the following way :

The first row in A is the first row in the new tensor, and the first row of B is the seocnd row in the new tensor, and the first row of C is the third row of the new tensor and so on and so forth.

So far I did it with for loops and this is not effictive at all. Would love to hear about more efficent ways.

Thanks

This should work:

```
a = torch.arange(0, 6).view(3, 2)
b = torch.arange(6, 12).view(3, 2)
c = torch.arange(12, 18).view(3, 2)
ret = torch.cat((a.unsqueeze(1), b.unsqueeze(1), c.unsqueeze(1)), dim=1).view(9, 2)
```

1 Like