diff options
author | jaimefrio <jaime.frio@gmail.com> | 2014-08-27 22:52:19 -0700 |
---|---|---|
committer | jaimefrio <jaime.frio@gmail.com> | 2014-08-27 22:52:19 -0700 |
commit | a85c17727fc573f1d0cc2e993792a8694eac581e (patch) | |
tree | 44c80e9ef8f227202e7e93dae3ca8132839e93ba /numpy/lib/arraysetops.py | |
parent | 0210cca2e10199dabc81b64fca2085ab62645b7f (diff) | |
download | numpy-a85c17727fc573f1d0cc2e993792a8694eac581e.tar.gz |
ENH: Speed up `unique` with `return_inverse`
This replaces a sort with fancy indexing.
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 2d98c35d2..5ace7146a 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -204,8 +204,9 @@ def unique(ar, return_index=False, return_inverse=False, return_counts=False): ret += (perm[flag],) if return_inverse: iflag = np.cumsum(flag) - 1 - iperm = perm.argsort() - ret += (np.take(iflag, iperm),) + inv_idx = np.empty_like(ar, dtype=np.intp) + inv_idx[perm] = iflag + ret += (inv_idx,) if return_counts: idx = np.concatenate(np.nonzero(flag) + ([ar.size],)) ret += (np.diff(idx),) |