本文簡要介紹 python 語言中 numpy.ix_
的用法。
用法:
numpy.ix_(*args)
從多個序列構造一個開放網格。
該函數采用 N 個一維序列並返回 N 個輸出,每個輸出具有 N 個維度,使得除了一維之外的所有形狀都為 1,並且具有非單位形狀值的維度在所有 N 維度中循環。
使用
ix_
可以快速構造索引數組來索引叉積。a[np.ix_([1,3],[2,5])]
返回數組[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]
。- args: 一維序列
每個序列應該是整數或布爾類型。布爾序列將被解釋為相應維度的布爾掩碼(相當於傳入
np.nonzero(boolean_sequence)
)。
- out: ndarray 的元組
N 個數組,每個數組有 N 維,N 是輸入序列的數量。這些陣列一起形成一個開放的網格。
參數:
返回:
例子:
>>> a = np.arange(10).reshape(2, 5) >>> a array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) >>> ixgrid = np.ix_([0, 1], [2, 4]) >>> ixgrid (array([[0], [1]]), array([[2, 4]])) >>> ixgrid[0].shape, ixgrid[1].shape ((2, 1), (1, 2)) >>> a[ixgrid] array([[2, 4], [7, 9]])
>>> ixgrid = np.ix_([True, True], [2, 4]) >>> a[ixgrid] array([[2, 4], [7, 9]]) >>> ixgrid = np.ix_([True, True], [False, False, True, False, True]) >>> a[ixgrid] array([[2, 4], [7, 9]])
相關用法
- Python numpy isclose用法及代碼示例
- Python numpy issctype用法及代碼示例
- Python numpy isnat用法及代碼示例
- Python numpy is_busday用法及代碼示例
- Python numpy isposinf用法及代碼示例
- Python numpy issubdtype用法及代碼示例
- Python numpy issubclass_用法及代碼示例
- Python numpy interp用法及代碼示例
- Python numpy issubsctype用法及代碼示例
- Python numpy iscomplexobj用法及代碼示例
- Python numpy iinfo用法及代碼示例
- Python numpy in1d用法及代碼示例
- Python numpy indices用法及代碼示例
- Python numpy isfinite用法及代碼示例
- Python numpy iscomplex用法及代碼示例
- Python numpy imag用法及代碼示例
- Python numpy isin用法及代碼示例
- Python numpy insert用法及代碼示例
- Python numpy i0用法及代碼示例
- Python numpy intersect1d用法及代碼示例
- Python numpy isinf用法及代碼示例
- Python numpy identity用法及代碼示例
- Python numpy isrealobj用法及代碼示例
- Python numpy ipmt用法及代碼示例
- Python numpy isscalar用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.ix_。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。