On Wed, Apr 14, 2010 at 11:16 AM, Nikolaus Rath <nikol...@rath.org> wrote: > 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).
Something like this might be made to work, if you want the max elements along all the rows. In [3]: a = np.asarray(a) In [4]: a[range(len(a)),np.argmax(a, axis=1)] Out[4]: array([8, 3]) Skipper _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion