From bdadc1ba29ea2852a31233aa521b59c7e223f31f Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 19 Sep 2006 00:17:10 +0000 Subject: Support empty arrays in setxor1d and setdiff1d. --- numpy/lib/arraysetops.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'numpy/lib/arraysetops.py') diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index a12185b41..e7c86e97c 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -89,6 +89,9 @@ def intersect1d_nu( ar1, ar2 ): 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 @@ def union1d( ar1, ar2 ): # 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 -- cgit v1.2.1