[Numpy-discussion] max argmax combo

Bill Baxter wbaxter at gmail.com
Mon Sep 18 21:21:19 CDT 2006


I find myself often wanting both the max and the argmax of an array.
(And same for the other arg* functions)
Of course I can do argmax first then use fancy indexing to get the max as well.
But the result of argmax isn't really in a format that's readily
usable as an index.
You have to do something like
    a = rand(10,5)
    imax = a.argmax(axis=0)
    vmax = a[(imax, range(5))]

Which isn't terrible, just always takes me a moment to remember the
proper indexing expression.
Would a way to get the argmax and the max at the same time be of
interest to anyone else?  Maybe an extra 'ret' arg on argmax?

   a = rand(10,5)
   imax,vmax = a.argmax(axis=0,retmax=True)

--Bill




More information about the Numpy-discussion mailing list