numpy.argwhere

numpy.argwhere(a)[源代码]

查找按元素分组的非零数组元素的索引。

参数
aarray_like

输入数据。

返回
index_array(N,a.ndim)ndarray公司

非零元素的索引。索引按元素分组。此阵列将具有形状 (N, a.ndim) 在哪里? N 是非零项的数目。

参见

where, nonzero

笔记

np.argwhere(a) 几乎和 np.transpose(np.nonzero(a)) ,但生成0D数组的正确形状的结果。

产量 argwhere 不适用于索引数组。为此目的使用 nonzero(a) 相反。

实例

>>> x = np.arange(6).reshape(2,3)
>>> x
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.argwhere(x>1)
array([[0, 2],
       [1, 0],
       [1, 1],
       [1, 2]])