diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2006-09-19 00:00:03 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2006-09-19 00:00:03 +0000 |
commit | 06db31eac5bf957778c5b95f813b4cd0d86ed012 (patch) | |
tree | af1a28c970b03c4f0c4718b5f64b38b1e3be7894 | |
parent | 371f8c6a1df8b2d244afd50d03e492d79a1372fe (diff) | |
download | numpy-06db31eac5bf957778c5b95f813b4cd0d86ed012.tar.gz |
Fix unique1d for empty sets. Closes r208.
-rw-r--r-- | numpy/lib/arraysetops.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index c7449eb12..a12185b41 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -48,20 +48,24 @@ def ediff1d(ary, to_end = None, to_begin = None): ## # 01.11.2005, c # 02.11.2005 -def unique1d( ar1, retindx = False ): +def unique1d(ar1, retindx=False): """Unique elements of 1D array. When ret_indx is True, return also the indices indx such that ar1.flat[indx] is the resulting array of unique elements.""" + ar = numpy.asarray(ar1).ravel() + if ar.size == 0: + if retindx: return numpy.empty(0, numpy.bool), ar + else: return ar + if retindx: - ar = numpy.array(ar1).ravel() perm = ar.argsort() aux = ar.take(perm) - flag = ediff1d( aux, 1 ) != 0 + flag = ediff1d(aux, 1) != 0 return perm.compress(flag), aux.compress(flag) + else: - ar = numpy.array( ar1 ).flatten() - ar.sort() - return ar.compress( ediff1d( ar, 1 ) != 0) + ar = numpy.array(sorted(ar)) + return ar.compress(ediff1d(ar, 1) != 0) ## # 01.11.2005, c |