调换轴值的顺序
# Create tensor with specific shape
x =torch.rand(size=(224, 224, 3))
#或者是x = torch.rand([224, 224, 3])
# Permute the original tensor to rearrange the axis order
x_permuted = x.permute(2, 0, 1)# shifts axis 0->1, 1->2, 2->0
print(f"Previous shape: {x.shape}")
print(f"New shape: {x_permuted.shape}")
#输出结果:
Previous shape: torch.Size([224, 224, 3])
New shape: torch.Size([3, 224, 224])