Pytorch permute not changing desired index
I am trying to use the permute function to swap the axis of my tensor but for some reason the output is not as expected. The output of the code is torch.Size([512, 256, 3, 3]) but I would expect it to be torch.Size([256, 512, 3, 3]). It doesn't look like I can use flip to switch 0, 1 index. Is there something i am missing? I wish to change the tensor such that the shape is (256, 512, 3, 3).
Reproducible code:
import torch

wtf = torch.rand(3, 3, 512, 256)
wtf = wtf.permute(2, 3, 1, 0)
print(wtf.shape)


The numbers provided to torch.permute are the indices of the axis in the order you want the new tensor to have.
Having set x as torch.rand(3, 3, 512, 256).

If you want to invert the order of axis: the initial order is 0, 1, 2, 3, you want 3, 2, 1, 0:
&gt;&gt;&gt; wtf.permute(3, 2, 1, 0).shape
torch.Size([256, 512, 3, 3])

Inverting axis order is essentially the transpose operation:
&gt;&gt;&gt; wtf.T
torch.Size([256, 512, 3, 3])


If you just want to invert and keep the order of the last two: original order is 0, 1, 2, 3 and resulting order is 3, 2, 0, 1:
&gt;&gt;&gt; x.permute(3, 2, 0, 1).shape
torch.Size([256, 512, 3, 3])



The difference between the two options is that the last two axes of size 3 will be swapped.
