From: Charles R H. <cha...@gm...> - 2006-09-19 02:56:43
|
On 9/18/06, Bill Baxter <wb...@gm...> wrote: > > 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) I don't generally like overloading return values, the function starts to lose its definition and becomes a bit baroque where simply changing a keyword value can destroy the viability of the following code. But I can see the utility of what you want. Hmm, this problem is not unique to argmax. Maybe what we need is a general way to extract values, something like extract(a, imax, axis=0) to go along with all the single axis functions. Chuck |