Nikolaus Rath <Nikolaus <at> rath.org> writes:

> 
> Hello,
> 
> How do I best find out the indices of the largest x elements in an
> array?
> 
> Example:
> 
> 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).
> 
> Best,
> 
>    -Niko
> 
Hi,

Just
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.

-eat


_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to