numpy.rollaxis#

numpy.rollaxis(a, axis, start=0)[原始碼]#

向後滾動指定的軸,直到它位於給定的位置。

為了向後相容性,此函式繼續受到支援,但您應該優先使用 moveaxismoveaxis 函式是在 NumPy 1.11 中新增的。

參數:
andarray

輸入陣列。

axisint

要滾動的軸。其他軸的位置彼此相對不變。

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)