[Numpy-svn] r3184 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Mon Sep 18 19:17:16 CDT 2006


Author: stefan
Date: 2006-09-18 19:17:10 -0500 (Mon, 18 Sep 2006)
New Revision: 3184

Modified:
   trunk/numpy/lib/arraysetops.py
Log:
Support empty arrays in setxor1d and setdiff1d.


Modified: trunk/numpy/lib/arraysetops.py
===================================================================
--- trunk/numpy/lib/arraysetops.py	2006-09-19 00:00:03 UTC (rev 3183)
+++ trunk/numpy/lib/arraysetops.py	2006-09-19 00:17:10 UTC (rev 3184)
@@ -89,6 +89,9 @@
 def setxor1d( ar1, ar2 ):
     """Set exclusive-or of 1D arrays with unique elements."""
     aux = numpy.concatenate((ar1, ar2))
+    if aux.size == 0:
+        return aux
+    
     aux.sort()
     flag = ediff1d(aux, to_end = 1, to_begin = 1) == 0
     flag2 = ediff1d(flag) == 0
@@ -129,8 +132,11 @@
 # 03.11.2005, c
 def setdiff1d( ar1, ar2 ):
     """Set difference of 1D arrays with unique elements."""
-    aux = setmember1d( ar1, ar2 )
-    return ar1.compress(aux == 0)
+    aux = setmember1d(ar1,ar2)
+    if aux.size == 0:
+        return aux
+    else:
+        return numpy.asarray(ar1).compress(aux == 0)
 
 ##
 # 02.11.2005, c



More information about the Numpy-svn mailing list