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.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)