How reshape 3D tensor of shape (3, 1, 2) to (1, 2, 3)
I intended

(Pdb) aa = torch.tensor([[[1,2]], [[3,4]], [[5,6]]])
(Pdb) aa.shape
torch.Size([3, 1, 2])
(Pdb) aa
tensor([[[ 1,  2]],

        [[ 3,  4]],

        [[ 5,  6]]])
(Pdb) aa.view(1, 2, 3)
tensor([[[ 1,  2,  3],
         [ 4,  5,  6]]])


But what I really want is

tensor([[[ 1,  3,  5],
         [ 2,  4,  6]]])


How?

In my application, I am trying to transform my input data of shape (L, N, C_in) to (N, C_in, L) in order to use Conv1d, where


L: sequence length
N: batch size
C_in: number of channels in the input, I also understand it as the dimensionality of the input at each position of a sequence.


I am also wondering the input of Conv1d doesn't have the same input shape as GRU?

You can permute the axes to the desired shape. (This is similar to numpy.moveaxis() operation).
In [90]: aa
Out[90]: 
tensor([[[ 1,  2]],

        [[ 3,  4]],

        [[ 5,  6]]])

In [91]: aa.shape
Out[91]: torch.Size([3, 1, 2])

# pass the desired ordering of the axes as argument
# assign the result back to some tensor since permute returns a &quot;view&quot;
In [97]: permuted = aa.permute(1, 2, 0)

In [98]: permuted.shape
Out[98]: torch.Size([1, 2, 3])

In [99]: permuted
Out[99]: 
tensor([[[ 1,  3,  5],
         [ 2,  4,  6]]])

