Home > Mobile >  What does "grouped by element" mean in numpy.argwhere documentation?
What does "grouped by element" mean in numpy.argwhere documentation?

Time:10-08

Numpy argwhere documentation says:

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

However the actual implementation is just

return transpose(nonzero(a))

So no reordering or grouping is performed.

I would expect that

import numpy as np
x = np.full((2,3),6)
x[:,1] = 5
np.argwhere(x)

would return

array([[0, 1],
       [1, 1],
       [0, 0],
       [0, 2],
       [1, 0],
       [1, 2]])

Instead it returns

array([[0, 0],
       [0, 1],
       [0, 2],
       [1, 0],
       [1, 1],
       [1, 2]])

Am I missing something or is it a bug in the documentation?

CodePudding user response:

[0,1] is the indices for one element of the array. [1,1] is for the next nonzero element. Don't try to read anything profound in that phrasing. It's just trying to contrast it with the tuple of arrays that np.nonzero returns. In nonzero the "grouping" is by dimension.

  • Related