Numpy 的 roll(~)
方法沿指定軸移動數組。
參數
1. a
| array_like
✜ 要執行該方法的數組。
2. shift
| integer
或 tuple
或 integers
✜ 所需的輪班數。
3. axis
| number
| optional
✜ 移動輸入數組的軸。
返回值
元素按指定量移動的 Numpy 數組。
例子
滾動平麵數組
要將平麵數組移動 1,請使用以下命令:
np.roll([1,2,3,4], 1)
array([4, 1, 2, 3])
請注意數組的最終值(即本例中的 4)是如何放置在最前麵的。
滾動二維數組
按值
要將二維數組移動 1,請使用以下命令:
np.roll([[1,2], [3,4]], 1)
array([[4, 1],
[2, 3]])
本質上,我們正在做的事情如下:
按行
要將 2D 數組按行移動 1 行,請添加 axis=0
參數:
np.roll([[1,2], [3,4], [5,6]], 1, axis=0)
array([[5, 6],
[1, 2],
[3, 4]])
本質上,我們正在做以下事情:
按欄目
要將 2D 數組按列移動 1,請添加 axis=1
參數:
np.roll([[1,2,3], [4,5,6]], 1, axis=1)
array([[3, 1, 2],
[6, 4, 5]])
本質上,我們正在做以下事情:
相關用法
- Python NumPy rot90方法用法及代碼示例
- Python round()用法及代碼示例
- Python NumPy roots方法用法及代碼示例
- Python round方法用法及代碼示例
- Python random.getstate()用法及代碼示例
- Python random.triangular()用法及代碼示例
- Python Numpy recarray.tostring()用法及代碼示例
- Python reduce()用法及代碼示例
- Python response.status_code用法及代碼示例
- Python Numpy recarray.tobytes()用法及代碼示例
- Python string rpartition()用法及代碼示例
- Python numpy random.mtrand.RandomState.randn用法及代碼示例
- Python randint()用法及代碼示例
- Python numpy random.mtrand.RandomState.rand用法及代碼示例
- Python Numpy recarray.min()用法及代碼示例
- Python response.request用法及代碼示例
- Python repr方法用法及代碼示例
- Python Numpy recarray.cumprod()用法及代碼示例
- Python numpy random.mtrand.RandomState.pareto用法及代碼示例
- Python re.compile用法及代碼示例
- Python NumPy remainder方法用法及代碼示例
- Python Django re_path用法及代碼示例
- Python response.elapsed用法及代碼示例
- Python numpy random.mtrand.RandomState.standard_normal用法及代碼示例
- Python response.cookies用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | roll method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。