summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2007-12-22 06:58:15 +0000
committerDavid Cournapeau <cournape@gmail.com>2007-12-22 06:58:15 +0000
commitb1729a124f68652ff57beff8f71ab71efbec2f10 (patch)
tree432045a080beae0b5cf9729d91026472c1f6f8af /numpy
parent5df69a90f90f2298f5631bb5000eedd8e0b03f07 (diff)
parentc7b8c2842dff3f62f1dba62cd4a3431377a68bd7 (diff)
downloadnumpy-b1729a124f68652ff57beff8f71ab71efbec2f10.tar.gz
Merged revisions 4612-4630 via svnmerge from
http://svn.scipy.org/svn/numpy/trunk ........ r4620 | cdavid | 2007-12-18 19:41:22 +0900 (Tue, 18 Dec 2007) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-4619" from http://svn.scipy.org/svn/numpy/branches/distutils_scons_command ........ r4624 | rc | 2007-12-20 19:30:45 +0900 (Thu, 20 Dec 2007) | 2 lines fixed setmember1d for string arrays ........ r4626 | stefan | 2007-12-21 18:00:24 +0900 (Fri, 21 Dec 2007) | 2 lines Add test for setdiff1d on character arrays. ........
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/arraysetops.py9
-rw-r--r--numpy/lib/tests/test_arraysetops.py4
2 files changed, 10 insertions, 3 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 6693fa81c..1d99f7a97 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -201,9 +201,13 @@ def setmember1d( ar1, ar2 ):
numpy.lib.arraysetops has a number of other functions for performing set
operations on arrays.
"""
- zlike = nm.zeros_like
+ ar1 = nm.asarray( ar1 )
+ ar2 = nm.asarray( ar2 )
ar = nm.concatenate( (ar1, ar2 ) )
- tt = nm.concatenate( (zlike( ar1 ), zlike( ar2 ) + 1) )
+ b1 = nm.zeros( ar1.shape, dtype = nm.int8 )
+ b2 = nm.ones( ar2.shape, dtype = nm.int8 )
+ tt = nm.concatenate( (b1, b2) )
+
# We need this to be a stable sort, so always use 'mergesort' here. The
# values from the first array should always come before the values from the
# second array.
@@ -212,7 +216,6 @@ def setmember1d( ar1, ar2 ):
aux2 = tt[perm]
# flag = ediff1d( aux, 1 ) == 0
flag = nm.concatenate( (aux[1:] == aux[:-1], [False] ) )
-
ii = nm.where( flag * aux2 )[0]
aux = perm[ii+1]
perm[ii+1] = perm[ii]
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index e2e703b9a..5a5a8fbd8 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -145,6 +145,10 @@ class TestAso(NumpyTestCase):
assert_array_equal([], setdiff1d([],[]))
+ def check_setdiff1d_char_array(self):
+ a = numpy.array(['a','b','c'])
+ b = numpy.array(['a','b','s'])
+ assert_array_equal(setdiff1d(a,b),numpy.array(['c']))
##
# 03.11.2005, c