[Numpy-discussion] argsort question
Travis Oliphant
oliphant.travis at ieee.org
Thu Jun 8 11:15:38 EDT 2006
Robert Cimrman wrote:
> Hi all,
>
> I have just lost some time to find a bug related to the fact, that
> argsort does not preserve the order of an array that is already sorted,
> see the example below. For me, it would be sufficient to mention this
> fact in the docstring, although having order preserving argsort is also
> an option :). What do the developers think?
>
> In [33]:a = nm.zeros( 10000 )
> In [34]:b = nm.arange( 10000 )
> In [35]:nm.alltrue( nm.argsort( a ) == b )
> Out[35]:False
>
>
You want a "stable" sorting algorithm like the "mergesort". Use the
argsort method with the mergesoret kind option:
a.argsort(kind='merge')
-Travis
More information about the NumPy-Discussion
mailing list