numpy.rollaxis

numpy.rollaxis(a, axis, start=0)[源代码]

向后滚动指定轴,直到其位于给定位置。

此函数继续支持向后兼容性,但您应该更喜欢 moveaxis . 这个 moveaxis 在numpy 1.11中添加了函数。

参数
a恩达雷

输入数组。

axis利息

要滚动的轴。其他轴的位置不会相对改变。

start可选的

什么时候? start <= axis ,轴将回滚,直到它位于该位置。什么时候? start > axis ,轴被滚动直到它位于该位置之前。默认值为0,结果为“完全”滚动。下表描述了 start 解释如下:

start

标准化 start

-(arr.ndim+1)

提升 AxisError

-arr.ndim

0

-1

arr.ndim-1

0

0

arr.ndim

arr.ndim

arr.ndim + 1

提升 AxisError

返回
res恩达雷

对于numpy>=1.10.0,视图 a 总是返回。对于早期的numpy版本, a 仅当更改轴的顺序时返回,否则返回输入数组。

参见

moveaxis

将阵列轴移动到新位置。

roll

沿给定轴将数组元素滚动若干位置。

实例

>>> a = np.ones((3,4,5,6))
>>> np.rollaxis(a, 3, 1).shape
(3, 6, 4, 5)
>>> np.rollaxis(a, 2).shape
(5, 3, 4, 6)
>>> np.rollaxis(a, 1, 4).shape
(3, 5, 6, 4)