numpy.rollaxis#

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

向后滚动指定的轴,直到它位于给定的位置.

为了向后兼容,此函数将继续被支持,但您应该优先使用 moveaxis . moveaxis 函数已在 NumPy 1.11 中添加.

参数:
andarray

输入数组.

int

要滚动的轴.其他轴的位置相对于彼此不改变.

startint, optional

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

返回:
resndarray

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

参见

moveaxis

将数组轴移动到新位置.

roll

沿给定轴按一定数量的位置滚动数组的元素.

示例

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