diff options
author | Christian Brueffer <christian@brueffer.de> | 2014-10-15 17:54:50 +0200 |
---|---|---|
committer | Christian Brueffer <christian@brueffer.de> | 2014-10-15 17:54:50 +0200 |
commit | 657c8b9106084ea284b3bd50f6edd6bfef880a50 (patch) | |
tree | 83f92d827975159341c37d9531405ab19a76cd05 /numpy/lib/arraysetops.py | |
parent | 2f1786306e696709481ccfc95b844d5aa2700b6d (diff) | |
download | numpy-657c8b9106084ea284b3bd50f6edd6bfef880a50.tar.gz |
Add examples for intersect1d and union1d of more than two arrays.
The approach was suggested by Jaime Frio in issue #5179.
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r-- | numpy/lib/arraysetops.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 5c3b504de..d3b6119f4 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -241,6 +241,11 @@ def intersect1d(ar1, ar2, assume_unique=False): >>> np.intersect1d([1, 3, 4, 3], [3, 1, 2, 1]) array([1, 3]) + To intersect more than two arrays, use functools.reduce: + + >>> from functools import reduce + >>> reduce(np.intersect1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2])) + array([3]) """ if not assume_unique: # Might be faster than unique( intersect1d( ar1, ar2 ) )? @@ -421,6 +426,11 @@ def union1d(ar1, ar2): >>> np.union1d([-1, 0, 1], [-2, 0, 2]) array([-2, -1, 0, 1, 2]) + To find the union of more than two arrays, use functools.reduce: + + >>> from functools import reduce + >>> reduce(np.union1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2])) + array([1, 2, 3, 4, 6]) """ return unique(np.concatenate((ar1, ar2))) |