[Numpy-discussion] argsort question

Charles R Harris charlesr.harris at gmail.com
Thu Jun 8 10:21:53 CDT 2006


Robert,

Argsort doesn't preserve order by default because quicksort is not a stable
sort. Try using the kind="merge" option and see what happens. Or try
lexsort, which is targeted at just this sort of sort and uses  merge sort.
See the documentation here.

http://scipy.org/Numpy_Example_List#head-9f8656795227e3c43e849c6c0435eeeb32afd722

Chuck

PS:  The function argsort doesn't seem to support this  extension in the
version I am using (time for another svn update), so you may have to do
something like

>>> a = empty(50)
>>> a.argsort(kind="merge")
array([48, 47, 46,  0,  1, 49, 37, 12, 22, 38, 11,  2, 10, 36, 40, 25, 18,
        6, 17,  4,  3, 20, 24, 43, 33,  9,  7, 35, 32,  8, 23, 21,  5, 28,
       31, 30, 29, 26, 27, 19, 44, 13, 14, 15, 34, 39, 41, 42, 16, 45])

On 6/8/06, Robert Cimrman <cimrman3 at ntc.zcu.cz> 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
>
> r.
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060608/9c6a7655/attachment-0001.html 


More information about the Numpy-discussion mailing list