I have three tensors of size [5x256x10], [5x256x10],[5x256x10]
. When i do concatenation along dim 0
i get [25x256x10]
but this does not concatenate along each sample in dim 0
. For example, i would to like to concatenate 0th row of tensor 1, 0th row of tensor 2 and 0th row of tensor 3 into [3x256x10]
similarly for rest 4 rows leading to [25x256x10]
. Any idea ?
Hi,
I assuming the result you got is [15x256x10]
and may the code snippet can help you.
tensor1 = torch.randn(5, 256, 10)
tensor2 = torch.randn(5, 256, 10)
tensor3 = torch.randn(5, 256, 10)
print(len(tensor1))
concat_slices=[]
for i in range(len(tensor1)):
sub_slice = torch.cat([tensor1[i].view(1, 256, 10), tensor2[i].view(1, 256, 10), tensor3[i].view(1, 256,10)], dim=0)
print(sub_slice.shape)
concat_slices.append(sub_slice)
tensor = torch.cat([sub_slice for sub_slice in concat_slices], dim=0)
print(tensor.shape)