numpy和torch中transpose的功能不同
numpy.ndarray.transpose的官方文档
torch.transpose的官方文档
numpy.transpose需指定一个新的axis的顺序
import numpy as np
array_ = np.arange(24).reshape(1,2,3,4)
print(array_)
# [[[[ 0 1 2 3]
# [ 4 5 6 7]
# [ 8 9 10 11]]
#
# [[12 13 14 15]
# [16 17 18 19]
# [20 21 22 23]]]]
array_t = array_.transpose([0,3,2,1])
print(array_t)
# [[[[ 0 12]
# [ 4 16]
# [ 8 20]]
#
# [[ 1 13]
# [ 5 17]
# [ 9 21]]
#
# [[ 2 14]
# [ 6 18]
# [10 22]]
#
# [[ 3 15]
# [ 7 19]
# [11 23]]]]
array_tt = array_.transpose([0,3,2,1])
print(array_tt)