# [NumPy-Tickets] [NumPy] #2063: unique() does not seem to return correct index if array larger than 16

NumPy Trac numpy-tickets@scipy....
Mon Mar 19 09:57:46 CDT 2012

```#2063: unique() does not seem to return correct index if array larger than 16
------------------------+---------------------------------------------------
Reporter:  lolowizard  |       Owner:  somebody
Type:  defect      |      Status:  new
Priority:  highest     |   Milestone:  1.7.0
Component:  numpy.core  |     Version:  1.6.1
Keywords:  unique      |
------------------------+---------------------------------------------------

Comment(by bryan):

Explicitly specifying mergesort seems to solve the problem:
{{{
In [6]: np.unique(w,return_index=True)
Out[6]: (array([0, 1, 2]), array([ 0,  5, 11]))

In [7]: np.unique(v,return_index=True)
Out[7]: (array([0, 1, 2]), array([ 0,  5, 11]))
}}}

{{{
index c4441d8..3ecc2d4 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -174,12 +174,12 @@ def unique(ar, return_index=False,
return_inverse=False):
return ar

if return_inverse or return_index:
-        perm = ar.argsort()
+        perm = ar.argsort(kind='mergesort')
aux = ar[perm]
flag = np.concatenate(([True], aux[1:] != aux[:-1]))
if return_inverse:
iflag = np.cumsum(flag) - 1
-            iperm = perm.argsort()
+            iperm = perm.argsort(kind='mergesort')
if return_index:
return aux[flag], perm[flag], iflag[iperm]
else:
}}}

--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2063#comment:3>
NumPy <http://projects.scipy.org/numpy>
My example project
```