[Numpy-discussion] argmax
Travis Oliphant
oliphant.travis at ieee.org
Wed May 10 10:19:06 EDT 2006
Ed Schofield wrote:
> Tim Hochberg wrote:
>
>> >>> m
>> matrix([[0, 1, 2],
>> [3, 4, 5],
>> [6, 7, 8]])
>> >>> m.argmax()
>> matrix([[8]])
>>
>> Does anyone else think that this is a fairly nonsensical result? Not
>> that this is specific to matrices, the array result is just as weird:
>>
>> >>> a
>> array([[0, 1, 2],
>> [3, 4, 5],
>> [6, 7, 8]])
>> >>> a.argmax()
>> 8
>>
>> Given that obj[obj.argmax()] should really equal obj.max(), argmax
>> with no axis specified should really either raise an exception or
>> return a tuple.
>>
>
> I came across this last week, and I came to a similar conclusion. I
> agree that a sequence of indices would be far more useful. This
> sequence could be either an array or a tuple:
>
>
but
a.flat[a.argmax()] == a.max()
works also.
I'm not convinced it's worth special-casing the argmax method because
a.flat exists already.
-Travis
More information about the NumPy-Discussion
mailing list