diff options
author | Bryan Van de Ven <bryan@laptop.local> | 2012-03-19 10:08:33 -0500 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2012-03-30 08:27:54 -0600 |
commit | dbf235169ed3386b359caaa9217f5280bf1d6749 (patch) | |
tree | 09ca74c170813e131b66660ae28ddb66c3d8ba27 /numpy/lib/arraysetops.py | |
parent | 960a86be3539f67ea5200d6fe22ae0e82324af30 (diff) | |
download | numpy-dbf235169ed3386b359caaa9217f5280bf1d6749.tar.gz |
BUG: ticket #2063, make unique return consistent index.
Make unique use mergesort when return_index is true. This quarantees that
the returned indices are of the first occurrence of the unique elements and
makes the behavior better defined and consistent.
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index c4441d8a5..91dd96f9c 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -112,8 +112,8 @@ def unique(ar, return_index=False, return_inverse=False): unique : ndarray The sorted unique values. unique_indices : ndarray, optional - The indices of the unique values in the (flattened) original array. - Only provided if `return_index` is True. + The indices of the first occurrences of the unique values in the + (flattened) original array. Only provided if `return_index` is True. unique_inverse : ndarray, optional The indices to reconstruct the (flattened) original array from the unique array. Only provided if `return_inverse` is True. @@ -174,7 +174,10 @@ def unique(ar, return_index=False, return_inverse=False): return ar if return_inverse or return_index: - perm = ar.argsort() + if return_index: + perm = ar.argsort(kind='mergesort') + else: + perm = ar.argsort() aux = ar[perm] flag = np.concatenate(([True], aux[1:] != aux[:-1])) if return_inverse: |