numpy.
argwhere
查找按元素分组的非零数组元素的索引。
输入数据。
非零元素的索引。索引按元素分组。此阵列将具有形状 (N, a.ndim) 在哪里? N 是非零项的数目。
(N, a.ndim)
N
参见
where
nonzero
笔记
np.argwhere(a) 几乎和 np.transpose(np.nonzero(a)) ,但生成0D数组的正确形状的结果。
np.argwhere(a)
np.transpose(np.nonzero(a))
产量 argwhere 不适用于索引数组。为此目的使用 nonzero(a) 相反。
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]])