From cba15d5ec3472ac167bdfe06f32dc07d6bbabd4d Mon Sep 17 00:00:00 2001 From: wufangjie Date: Thu, 27 Jul 2017 11:21:05 +0800 Subject: make `setxor1d' a bit clear and speed up We need to find the index which is not the same with the left and right, I think np.logical_and's meaning is more clear and I test this got a speed up --- numpy/lib/arraysetops.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'numpy/lib/arraysetops.py') diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 9b0a1193f..a454b8725 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -378,8 +378,9 @@ def setxor1d(ar1, ar2, assume_unique=False): # flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True])) # flag2 = ediff1d( flag ) == 0 - flag2 = flag[1:] == flag[:-1] - return aux[flag2] +# flag2 = flag[1:] == flag[:-1] +# return aux[flag2] + return aux[np.logical_and(flag[1:], flag[:-1])] def in1d(ar1, ar2, assume_unique=False, invert=False): -- cgit v1.2.1