[Numpy-discussion] default behavior of argsort

Chris Barker Chris.Barker at noaa.gov
Fri May 14 21:05:14 EDT 2010


>>  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.
> 
> Right. Changing behavior on an edge case makes everyone else have to
> deal with that edge case in their code.

not to hammer a point home (OK, it IS to hammer a point home), this is 
one of the things that drove me crazy about MATLAB -- everything was a 
2-d array, unless one dimension happened to have length 1, and then some 
(but not all) functions treated it as 1-d. I had to write me own version 
of sum() for instance, that would sum over the last dimension, even if 
it happened to be 1.

numpy provides n-d arrays, so you don't have that silliness -- if you 
want a 1-d array, use a 1-d array.

I can't find it right now, but I'm pretty sure there is a function that 
will re-shape an array to remove the length-1 dimensions -- maybe that's 
what the OP needs.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list