Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to understand the np.argwhere function?

Tags:

numpy

Signature: np.argwhere(a)
Docstring:
Find the indices of array elements that are non-zero, grouped by element.

Examples

>>> 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]])

What does it mean by 'non-zero' and 'grouped by element'? and what is "x>1"?

like image 355
user697911 Avatar asked Sep 19 '18 07:09

user697911


1 Answers

In each row the first entry is the row index and the second entry is the column index of the entries of x that satisfy the condition.

For example: 2 is greater than 1 so the first row of argwhere gives you [0, 2] pointing to the position of 2 in x.

like image 82
idnavid Avatar answered Nov 04 '22 03:11

idnavid