注意:维数从0开始,0维 1维2维…,负数代表从右往左数,-1代表第一维,以此类推
import torchimport numpy as np# 创建一个二维数组arr = torch.tensor([[[1, 2], [3, 4]],[[5, 6], [7, 8]]])print("原始数组:")print(arr)# torch.transpose转置数组, dim的顺序谁先谁后没有关系,不影响最后结果!!!# transpose 调换;移项;颠倒顺序transposed_arr = arr.transpose(0, 1)print("转置后的数组:")print(transposed_arr)print("-----------------------------------------------------")transposed_arr = arr.transpose(-1, -2)print("转置后的数组:")print(transposed_arr)