numpy.rollaxis#
- numpy.rollaxis(a, axis, start=0)[source]#
向后滚动指定的轴,直到它位于给定的位置。
此函数仍受支持以向后兼容,但您应优先使用
moveaxis。moveaxis函数已于 NumPy 1.11 添加。- 参数:
- andarray
输入数组。
- axisint
将被滚动到的轴。其他轴相对于彼此的位置不变。
- startint, optional
当
start <= axis时,轴向后滚动直到位于该位置。当start > axis时,轴向前滚动直到位于该位置之前。默认值 0 会产生“完全”滚动。下表描述了start的负值如何解释start标准化
start-(arr.ndim+1)引发
AxisError-arr.ndim0
⋮
⋮
-1arr.ndim-100⋮
⋮
arr.ndimarr.ndimarr.ndim + 1引发
AxisError
- 返回:
- resndarray
对于 NumPy >= 1.10.0,始终返回 a 的视图。对于早期 NumPy 版本,仅当轴的顺序更改时才返回 a 的视图,否则返回输入数组。
示例
>>> 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)