[Numpy-svn] r3183 - trunk/numpy/lib
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Sep 18 20:00:10 EDT 2006
Author: stefan
Date: 2006-09-18 19:00:03 -0500 (Mon, 18 Sep 2006)
New Revision: 3183
Modified:
trunk/numpy/lib/arraysetops.py
Log:
Fix unique1d for empty sets. Closes r208.
Modified: trunk/numpy/lib/arraysetops.py
===================================================================
--- trunk/numpy/lib/arraysetops.py 2006-09-18 23:27:24 UTC (rev 3182)
+++ trunk/numpy/lib/arraysetops.py 2006-09-19 00:00:03 UTC (rev 3183)
@@ -48,20 +48,24 @@
##
# 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
More information about the Numpy-svn
mailing list