-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Adding isin function for multidimensional arrays #8423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
17faf5a
34a40da
2b4a81b
db5e5fd
f63cf31
a9bce34
f06ed40
0938763
e10ee1e
0ec089a
ba10c98
e72b686
818337d
6ace52e
7712179
a2c9b6c
552a193
fa0b0be
0ff6be4
545df63
41e5b0b
521d517
8805bbb
4d3f67c
0395f39
3d809a6
d22cafc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -490,15 +490,15 @@ def in1d(ar1, ar2, assume_unique=False, invert=False): | |
return ret[rev_idx] | ||
|
||
|
||
def isin(elements, test_elements, assume_unique=False, invert=False): | ||
def isin(element, test_elements, assume_unique=False, invert=False): | ||
""" | ||
Test whether each element of an array is also present in a second array. | ||
Calculates `element in test_elements`, broadcasting over `element` only. | ||
Returns a boolean array of the same shape as `elements` that is True | ||
where an element of `elements` is in `test_elements` and False otherwise. | ||
|
||
Parameters | ||
---------- | ||
elements : array_like | ||
element : array_like | ||
Input array. | ||
test_elements : array_like | ||
The values against which to test each value of `elements`. | ||
|
@@ -516,7 +516,7 @@ def isin(elements, test_elements, assume_unique=False, invert=False): | |
Returns | ||
------- | ||
isin : ndarray, bool | ||
Has the same shape as `elements`. The values `elements[isin]` | ||
Has the same shape as `element`. The values `elements[isin]` | ||
are in `test_elements`. | ||
|
||
See Also | ||
|
@@ -527,36 +527,36 @@ def isin(elements, test_elements, assume_unique=False, invert=False): | |
Notes | ||
----- | ||
|
||
`isin` can be considered as an element-wise function version of the | ||
python keyword `in`. ``isin(a, b)`` is roughly equivalent to | ||
`isin` is an element-wise function version of the python keyword `in`. | ||
``isin(a, b)`` is roughly equivalent to | ||
``np.array([item in b for item in a])`` if `a` and `b` are 1-D sequences. | ||
If `test_elements` is a set (or other non-sequence collection) it will | ||
be converted to an object array with one element, rather than an array | ||
of the values contained in `test_elements`. Converting the set to | ||
|
||
If `test_elements` is a set (or other non-sequence collection) it will | ||
be converted to an object array with one element, rather than an array | ||
of the values contained in `test_elements`. Converting the set to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth pointing out that this is just the |
||
a list usually gives the desired behavior. | ||
|
||
.. versionadded:: 1.13.0 | ||
|
||
Examples | ||
-------- | ||
>>> elements = np.array([[0, 2], [4, 6]]) | ||
>>> element = np.array([[0, 2], [4, 6]]) | ||
>>> test_elements = [1, 2, 4, 8] | ||
>>> mask = np.isin(elements, test_elements) | ||
>>> mask = np.isin(element, test_elements) | ||
>>> mask | ||
array([[ False, True], | ||
[ True, False]], dtype=bool) | ||
>>> elements[mask] | ||
>>> element[mask] | ||
array([2, 4]) | ||
>>> mask = np.isin(elements, test_elements, invert=True) | ||
>>> mask = np.isin(element, test_elements, invert=True) | ||
>>> mask | ||
array([[ True, False], | ||
[ False, True]], dtype=bool) | ||
>>> elements[mask] | ||
>>> element[mask] | ||
array([0, 6])""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: needs an extra newline in this docstring |
||
elements = np.array(elements) | ||
return in1d(elements, test_elements, assume_unique=assume_unique, | ||
invert=invert).reshape(elements.shape) | ||
element = np.array(element) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
return in1d(element, test_elements, assume_unique=assume_unique, | ||
invert=invert).reshape(element.shape) | ||
|
||
|
||
def union1d(ar1, ar2): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1183,12 +1183,12 @@ def in1d(ar1, ar2, assume_unique=False, invert=False): | |
return flag[indx][rev_idx] | ||
|
||
|
||
def isin(elements, test_elements, assume_unique=False, invert=False): | ||
def isin(element, test_elements, assume_unique=False, invert=False): | ||
""" | ||
Test whether each element of an array is also present in a second | ||
array. | ||
Calculates `element in test_elements`, broadcasting over | ||
`element` only. | ||
|
||
The output is always a masked array of the same shape as `elements`. | ||
The output is always a masked array of the same shape as `element`. | ||
See `numpy.isin` for more details. | ||
|
||
See Also | ||
|
@@ -1201,9 +1201,9 @@ def isin(elements, test_elements, assume_unique=False, invert=False): | |
.. versionadded:: 1.13.0 | ||
|
||
""" | ||
elements = ma.array(elements) | ||
return in1d(elements, test_elements, assume_unique=assume_unique, | ||
invert=invert).reshape(elements.shape) | ||
element = ma.array(element) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, |
||
return in1d(element, test_elements, assume_unique=assume_unique, | ||
invert=invert).reshape(element.shape) | ||
|
||
|
||
def union1d(ar1, ar2): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed an
s
here