[NumPy-Tickets] [NumPy] #1486: Add option to use stable sorting algorithm in unique(1d)

NumPy Trac numpy-tickets@scipy....
Tue May 18 14:45:10 CDT 2010

#1486: Add option to use stable sorting algorithm in unique(1d)
 Reporter:  bverheg                |       Owner:  somebody
     Type:  enhancement            |      Status:  new     
 Priority:  normal                 |   Milestone:          
Component:  numpy.lib              |     Version:          
 Keywords:  unique stable sorting  |  
 The unique/1d function in arraysetops.py returns the index of the unique
 elements in an array (when using the argument return_index=True), but in
 case of equal elements it is undetermined which of the multiple indices
 will be returned.

 I often need to find the ''first'' occurence of each of the unique
 elements in the array. The most elegant way I have come up with to achieve
 this, is to create a minor variation of unique/1d, using a stable sorting
 algorithm ('mergesort') instead of the 'quicksort' default, at this place
 in the code:

     if return_inverse or return_index:
         perm = ar.argsort(kind='mergesort')
         aux = ar[perm]

 I suggest therefore to add an argument to the unique/1d function to allow
 the selection of the stable 'mergesort' algorithm at the place shown
 above. In my opinion, it does not make much sense to use this slower
 algorithm also in the other sort operations in unique/1d.

Ticket URL: <http://projects.scipy.org/numpy/ticket/1486>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list