summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorseberg <sebastian@sipsolutions.net>2014-08-28 09:34:38 +0100
committerseberg <sebastian@sipsolutions.net>2014-08-28 09:34:38 +0100
commit036efee0caf0bf026a9e8a9fd2010be11c7d9408 (patch)
tree44c80e9ef8f227202e7e93dae3ca8132839e93ba /numpy/lib/arraysetops.py
parent0210cca2e10199dabc81b64fca2085ab62645b7f (diff)
parenta85c17727fc573f1d0cc2e993792a8694eac581e (diff)
downloadnumpy-036efee0caf0bf026a9e8a9fd2010be11c7d9408.tar.gz
Merge pull request #5012 from jaimefrio/faster_return_inverse
ENH: Speed up `unique` with `return_inverse`
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py5
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),)