How can I swap axis in a torch tensor?

Viewed 6415

I have a torch tensor of size torch.Size([1, 128, 56, 128])

1 is channel, 128 is the width, and height. 56 are the stacks of images.

How can I resize it to torch.Size([1, 56, 128, 128]) ?

2 Answers

You could simply use permute or transpose.

You can use the swapaxes function:

my_tensor.swapaxes(1,2)
Related