[Numpy-discussion] Find indices of largest elements
Wed Apr 14 16:35:37 CDT 2010
Nikolaus Rath <Nikolaus <at> rath.org> writes:
> How do I best find out the indices of the largest x elements in an
> a = [ [1,8,2], [2,1,3] ]
> magic_function(a, 2) == [ (0,1), (1,2) ]
> Since the largest 2 elements are at positions (0,1) and (1,2).
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.
More information about the NumPy-Discussion