本文簡要介紹 python 語言中 numpy.ndindex
的用法。
用法:
class numpy.ndindex(*shape)
用於索引數組的 N 維迭代器對象。
給定數組的形狀,
ndindex
實例會迭代數組的 N 維索引。每次迭代都會返回一個索引元組,首先迭代最後一個維度。- shape: 整數,或單個整數元組
數組每個維度的大小可以作為單獨的參數或作為元組的元素傳遞。
參數:
例子:
維度作為單獨的參數
>>> for index in np.ndindex(3, 2, 1): ... print(index) (0, 0, 0) (0, 1, 0) (1, 0, 0) (1, 1, 0) (2, 0, 0) (2, 1, 0)
相同的維度 - 但在一個元組中
(3, 2, 1)
>>> for index in np.ndindex((3, 2, 1)): ... print(index) (0, 0, 0) (0, 1, 0) (1, 0, 0) (1, 1, 0) (2, 0, 0) (2, 1, 0)
相關用法
- Python numpy nditer.copy用法及代碼示例
- Python numpy nditer用法及代碼示例
- Python numpy ndarray.astype用法及代碼示例
- Python numpy ndarray.flat用法及代碼示例
- Python numpy ndarray.setflags用法及代碼示例
- Python numpy ndarray.setfield用法及代碼示例
- Python numpy ndarray.sort用法及代碼示例
- Python numpy ndarray.real用法及代碼示例
- Python numpy ndarray.strides用法及代碼示例
- Python numpy ndarray.itemset用法及代碼示例
- Python numpy ndarray.__class_getitem__用法及代碼示例
- Python numpy ndarray.partition用法及代碼示例
- Python numpy ndarray.transpose用法及代碼示例
- Python numpy ndarray.flatten用法及代碼示例
- Python numpy ndarray.resize用法及代碼示例
- Python numpy ndarray.dtype用法及代碼示例
- Python numpy ndarray.imag用法及代碼示例
- Python numpy ndarray.dot用法及代碼示例
- Python numpy ndarray.size用法及代碼示例
- Python numpy ndarray.fill用法及代碼示例
- Python numpy ndarray.item用法及代碼示例
- Python numpy ndarray.nbytes用法及代碼示例
- Python numpy ndarray.tobytes用法及代碼示例
- Python numpy ndarray.copy用法及代碼示例
- Python numpy ndarray.ctypes用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.ndindex。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。