Signature: np.argwhere(a)
Docstring:
Find the indices of array elements that are non-zero, grouped by element.
Run Code Online (Sandbox Code Playgroud)
>>> 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]])
Run Code Online (Sandbox Code Playgroud)
“非零”和“按元素分组”是什么意思?什么是“x>1”?
查找非零(true)的数组元素的索引(位置),按元素分组(每个索引都是其自己的行)。
基本上,如果您传递一个布尔数组,您将找到该数组为 true 的索引,但经过转置,以便表单中的索引[[x1, x2, ...], [y1, y2, ...]]变为表单[[x1, y1], [x2, y2], ...]。
x > 1是一个布尔数组,True随时随地。在你的例子中,它看起来像x > 1Falsex <= 1
[[False, False, True],
[True, True, True]]
Run Code Online (Sandbox Code Playgroud)