diff options
Diffstat (limited to 'numpy/lib')
-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 |