On Wed, Apr 14, 2010 at 10: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). > > I[1]: a = np.array([ [1,8,2], [2,1,3] ]) I[2]: b = a.max(axis=1)[:,np.newaxis] I[3]: b O[3]: array([[8], [3]]) I[4]: np.where(a==b) O[4]: (array([0, 1]), array([1, 2])) -- Gökhan
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion