diff options
author | Julien Phalip <jphalip@gmail.com> | 2013-02-20 06:44:50 +0000 |
---|---|---|
committer | Julien Phalip <jphalip@gmail.com> | 2013-04-08 22:21:31 -0700 |
commit | a3f2e0461eeec2077e7ed1f71bf1e0756e893257 (patch) | |
tree | 89c1fb09c34519d907249293f3a7ef8ed587da5e /numpy/ma/extras.py | |
parent | d1b195d943da80cafd42f935fa9ec920eb18c7e5 (diff) | |
download | numpy-a3f2e0461eeec2077e7ed1f71bf1e0756e893257.tar.gz |
ENH: add `invert` parameter to numpy.in1d().
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index a809db53c..861fefad0 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -1121,7 +1121,7 @@ def setxor1d(ar1, ar2, assume_unique=False): flag2 = (flag[1:] == flag[:-1]) return aux[flag2] -def in1d(ar1, ar2, assume_unique=False): +def in1d(ar1, ar2, assume_unique=False, invert=False): """ Test whether each element of an array is also present in a second array. @@ -1147,8 +1147,11 @@ def in1d(ar1, ar2, assume_unique=False): # the values from the second array. order = ar.argsort(kind='mergesort') sar = ar[order] - equal_adj = (sar[1:] == sar[:-1]) - flag = ma.concatenate((equal_adj, [False])) + if invert: + bool_ar = (sar[1:] != sar[:-1]) + else: + bool_ar = (sar[1:] == sar[:-1]) + flag = ma.concatenate((bool_ar, [invert])) indx = order.argsort(kind='mergesort')[:len(ar1)] if assume_unique: |