[Numpy-discussion] Applying argwhere to an array
Robert Kern
robert.kern at gmail.com
Fri Nov 20 02:36:21 EST 2009
On Fri, Nov 20, 2009 at 01:21, - <hspotter2002 at gmail.com> wrote:
> So if I have a 2-dimensional array, and I want to return the indexes
> of all the elements that are larger than some value, then I just use
> np.argwhere(d > 1) or something, where d is the array. However, is
> there anything I can do that's similar, but return the indexes of the
> elements that are larger than a value, where the value depends on the
> column index? Like if the column index is less than 5 then do
> np.argwhere(d > 1) and np.argwhere(d > 2) otherwise. I know I can
> split up the array and then apply these on both arrays, but then I end
> up with an unsorted list if I want the indexes to be sorted by rows,
> so I'd have to deal with that also, which would take up a lot of time.
> So if anyone knows what I should do, that would be great. Thanks.
Comparisons are just operators like +-/* and array broadcasting works
on them, too. So, if d.shape == (N, 10), let's say, then you could do:
np.argwhere(d > [1,1,1,1,1,2,2,2,2,2])
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list