How I can swap 3 dimensions with each other in Pytorch?
I have a a= torch.randn(28, 28, 8) and I want to swap the dimensions of the tensor and move the third dimension to the first place, first one to the second place and the second one to the third place. I used  b = a.transpose(2, 0, 1) , but I received this error:

TypeError: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of:
 * (name dim0, name dim1)
 * (int dim0, int dim1)


Should I use transpose several times, each time only to swap two dimensions? Is there any way that I can swap all at once?

Thanks.

You can use Pytorch's permute() function to swap all at once,

&gt;&gt;&gt;a = torch.randn(28, 28, 8)
&gt;&gt;&gt;b = a.permute(2, 0, 1)
&gt;&gt;&gt;b.shape
torch.Size([8, 28, 28])

