[Numpy-discussion] Strange behavior for argsort() and take()
Thomas J. Duck
tom.duck@dal...
Wed Jun 18 08:55:19 CDT 2008
Hi,
I have found what I think is some strange behavior for argsort
() and take(). First, here is an example that works as expected:
>>> x = numpy.array([1,0,3,2])
>>> x.argsort()
array([1, 0, 3, 2])
argsort() returns the original array, which is self-indexing for
numbers 0 through 3...
>>> x.take(x.argsort())
array([0, 1, 2, 3])
...and take() provides the correct sort with ascending order.
Now check out what happens when we swap the middle two numbers:
>>> x = numpy.array([1,3,0,2])
>>> x.argsort()
array([2, 0, 3, 1])
argsort() appears to have indexed the numbers in descending order
(which was not expected)....
>>> x.take(x.argsort())
array([0, 1, 2, 3])
... but the take() operation puts them in ascending order anyway
(which was really not expected)!
Can anyone shed some light on what is happening here for me? I
have tested this on both my OS X/Fink and Debian/Lenny systems with
the same result.
Thanks,
Tom
--
Thomas J. Duck <tom.duck@dal.ca>
Associate Professor,
Department of Physics and Atmospheric Science, Dalhousie University,
Halifax, Nova Scotia, Canada, B3H 3J5.
Tel: (902)494-1456 | Fax: (902)494-5191 | Lab: (902)494-3813
Web: http://aolab.phys.dal.ca/
More information about the Numpy-discussion
mailing list