[Numpy-discussion] Find indices of largest elements
Thu Apr 15 14:45:28 CDT 2010
eat <firstname.lastname@example.org> writes:
>> How do I best find out the indices of the largest x elements in an
> a= np.asarray([[1, 8, 2], [2, 1, 3]])
> print np.where((a.T== a.max(axis= 1)).T)
> However, if any row contains more than 1 max entity, above will fail. Please
> let me to know if that's relevant for you.
Not quite, because I'm interested in the n largest values over all
elements, not the largest element in each row or column. But Keith's
solution seems to work fine, even though I'm still struggling to
understand what's going on there :-).
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the NumPy-Discussion