[Numpy-discussion] Getting index of array after applying cond
eat
e.antero.tammi@gmail....
Fri Apr 2 14:00:26 CDT 2010
Shailendra <shailendra.vikas <at> gmail.com> writes:
>
> I forgot to mention that i wanted this to work for general shape. So i
> modified it little bit
>
> >>> x = array([[1,2,3,4,5], [6,7,8,7,6], [1,2,3,4,5]])
> >>> cond = (x > 5)
> >>> loc= where(cond)
> >>> arg_max=argmax(x[cond])
> >>> x[tuple([e[arg_max] for e in loc])]
> 8
But what happens if your x is for example
x = array([[1,2,3,4,5], [6,8,8,8,6], [1,2,3,4,5]])
x[tuple([e[arg_max] for e in loc])]
would still yield to 8,
which may or may not be an acceptable answer.
Basically what I mean is that why to bother with the argmax at all,
if your only interest is x[cond].max()?
Just my 2 cents.
Regards,
eat
More information about the NumPy-Discussion
mailing list