详解Python的transpose函数
数组转置和换轴import numpy as np>>> arr = np.arange(16).reshape((2,2,4))array([[[ 0,1,2,3],[ 4,5,6,7]],[[ 8,9, 10, 11],[12, 13, 14, 15]]])>>> arr.transpose((1,0,2))array([[[ 0,1,2,3],
·
数组转置和换轴
import numpy as np
>>> arr = np.arange(16).reshape((2,2,4))
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7]],
[[ 8, 9, 10, 11],
[12, 13, 14, 15]]])
>>> arr.transpose((1, 0, 2))
array([[[ 0, 1, 2, 3],
[ 8, 9, 10, 11]],
[[ 4, 5, 6, 7],
[12, 13, 14, 15]]])
transpose方法可以接收包含轴编号的元组,用于置换轴。本例中,9 的坐标为arr[1,0,1],经过transpose((1,0,2))变换以后,变为arr[0,1,1]
参考2维数组的转置
>>> arr = np.arange(15).reshape((3,5))
>>> arr
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
>>> arr.T
array([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]])
其它链接:
Python numpy.transpose 详解_November丶Chopin的博客-CSDN博客_numpy transpose
更多推荐
已为社区贡献28条内容
所有评论(0)