dask.array.moveaxis

dask.array.moveaxis

dask.array.moveaxis(a, source, destination)[源代码]

将数组的轴移动到新位置。

此文档字符串是从 numpy.moveaxis 复制的。

Dask 版本可能存在一些不一致性。

其他轴保持其原始顺序。

1.11.0 新版功能.

参数
anp.ndarray

应重新排序其轴的数组。

源代码整数或整数序列

要移动的轴的原始位置。这些位置必须是唯一的。

目的地整数或整数序列

每个原始轴的目标位置。这些也必须是唯一的。

返回
结果np.ndarray

移动轴后的数组。该数组是输入数组的视图。

参见

transpose

置换数组的维度。

swapaxes

交换数组的两个轴。

示例

>>> import numpy as np  
>>> 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)