[Numpy-discussion] Find the N maximum values and corresponding indexes in an array
Pierre GM
pgmdevlist@gmail....
Wed Dec 2 18:10:32 CST 2009
On Dec 2, 2009, at 6:55 PM, Howard Chong wrote:
>
> My question is: how can I make the latter version run faster? I think the answer is that I have to do the iteration in C.
>
> If that's the case, can anyone point me to where np.array.argmax() is implemented so I can write np.array.argmaxN() extend it to the N largest values?
What about using .argsort and take the last N values ?
>>> x=np.array([10,40,30,50,20])
>>> i=x.argsort()[-2:]
>>> (i,x[i])
(array([1, 3]), array([40, 50]))
More information about the NumPy-Discussion
mailing list