[Numpy-discussion] default behavior of argsort
Eric Firing
efiring at hawaii.edu
Fri May 14 17:29:32 EDT 2010
On 05/14/2010 11:03 AM, Dr. Phillip M. Feldman wrote:
>
>
>
> Robert Kern-2 wrote:
>>
>> On Wed, May 12, 2010 at 20:19, Dr. Phillip M. Feldman
>> <pfeldman at verizon.net> wrote:
>>>
>>> When operating on an array whose last dimension is unity, the default
>>> behavior of argsort is not very useful:
>>>
>>> |6> x=random.random((4,1))
>>> |7> shape(x)
>>> <7> (4, 1)
>>> |8> argsort(x)
>>> <8>
>>> array([[0],
>>> [0],
>>> [0],
>>> [0]])
>>> |9> argsort(x,axis=0)
>>> <9>
>>> array([[0],
>>> [2],
>>> [1],
>>> [3]])
>>
>> Sorry, but I don't think we are going to add a special case for this.
>>
>> --
>> Robert Kern
>>
>
> I don't see this as a special case. When axis is unspecified, the default
> is axis=-1, which causes argsort to operate on the last dimension. A more
> sensible default would be the last non-unity dimension.
That would be too clever for my liking. First, a default should be
something that can also be explicitly specified; how would you use the
axis kwarg to specify the last non-unit dimension? Second, treating a
unit dimension differently from a non-unit dimension *is* making it a
special case, and often--usually--one does not want that. It is
perfectly reasonable to have an algorithm that uses values sorted along
the last axis, even if that dimension sometimes turns out to be one.
Eric
>
> Phillip
More information about the NumPy-Discussion
mailing list