np.transpose
作用于一维数据,shape只有一个参数
没有效果
tt=np.array([0,1,2,3,4])
ttT=np.transpose(tt)
print("ttshape:",tt.shape)
print("ttTshape:",ttT.shape)
print("------------转置----------------")
print("tt:",tt)
print("------------转置后----------------")
print("ttT:",ttT)
输出以下
ttshape: (5,)
ttTshape: (5,)
------------转置----------------
tt: [0 1 2 3 4]
------------转置后----------------
ttT: [0 1 2 3 4]
作用于三维,shape为(x,x,x)
print("------------转置前----------------")
aa=np.array([[[ 1,2,3],[4,5,6]],[[7,8,9], [0,1,2]]])
print("aa.s:",aa.shape)
print(aa)
print("------------转置后----------------")
bb=np.transpose(aa,[2,0,1])
print("bb.s:",bb.shape)
print(bb)
输出以下:
------------转置前----------------
aa.s: (2, 2, 3)
[[[1 2 3]
[4 5 6]]
[[7 8 9]
[0 1 2]]]
------------转置后----------------
bb.s: (3, 2, 2)
[[[1 4]
[7 0]]
[[2 5]
[8 1]]
[[3 6]
[9 2]]]
作用于四维,shape为(x,x,x,x)
cc=np.array([[[[ 1,2,3],[4,5,6]],[[7,8,9], [0,1,2]]],[[[ 11,12,13],[14,15,16]],[[17,18,19], [20,21,22]]]])
print("------------转置前----------------")
print("cc.s:",cc.shape)
print("cc:",cc)
print("------------转置后----------------")
dd=np.transpose(cc,[0,3,1,2])
print("dd.s:",dd.shape)
print(dd)
输出以下:
------------转置前----------------
cc.s: (2, 2, 2, 3)
cc: [[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[ 0 1 2]]]
[[[11 12 13]
[14 15 16]]
[[17 18 19]
[20 21 22]]]]
------------转置后----------------
dd.s: (2, 3, 2, 2)
[[[[ 1 4]
[ 7 0]]
[[ 2 5]
[ 8 1]]
[[ 3 6]
[ 9 2]]]
[[[11 14]
[17 20]]
[[12 15]
[18 21]]
[[13 16]
[19 22]]]]