numpy.moveaxis
numpy.moveaxis(a, source, destination) [source]
将数组的轴移到新位置。
其他轴保持其原始顺序。
1.11.0版中的新功能。
参数 : | a : 轴应重新排序的数组。 source :int 或 int的sequence 要移动的轴的原始位置。 这些必须是唯一的。 destination :int 或 int的sequence 每个原始轴的目标位置。 这些也必须是唯一的。 |
返回值 : | result :np.ndarray 具有移动轴的Array。 该数组是输入数组的视图。 |
例子
>>> x = np.zeros((3, 4, 5)) >>> np.moveaxis(x, 0, -1).shape (4, 5, 3) >>> np.moveaxis(x, -1, 0).shape (5, 3, 4)
这些都达到相同的结果:
>>> np.transpose(x).shape (5, 4, 3) >>> np.swapaxes(x, 0, -1).shape (5, 4, 3) >>> np.moveaxis(x, [0, 1], [-1, -2]).shape (5, 4, 3) >>> np.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape (5, 4, 3)