Calculates ``element in test_elements``, broadcasting over `element` only. Returns a boolean array of the same shape as `element` that is True where an element of `element` is in `test_elements` and False otherwise. Parameters ---------- element : array_like Input a
(element, test_elements, assume_unique=False, invert=False, *,
kind=None)
| 765 | |
| 766 | @array_function_dispatch(_isin_dispatcher) |
| 767 | def isin(element, test_elements, assume_unique=False, invert=False, *, |
| 768 | kind=None): |
| 769 | """ |
| 770 | Calculates ``element in test_elements``, broadcasting over `element` only. |
| 771 | Returns a boolean array of the same shape as `element` that is True |
| 772 | where an element of `element` is in `test_elements` and False otherwise. |
| 773 | |
| 774 | Parameters |
| 775 | ---------- |
| 776 | element : array_like |
| 777 | Input array. |
| 778 | test_elements : array_like |
| 779 | The values against which to test each value of `element`. |
| 780 | This argument is flattened if it is an array or array_like. |
| 781 | See notes for behavior with non-array-like parameters. |
| 782 | assume_unique : bool, optional |
| 783 | If True, the input arrays are both assumed to be unique, which |
| 784 | can speed up the calculation. Default is False. |
| 785 | invert : bool, optional |
| 786 | If True, the values in the returned array are inverted, as if |
| 787 | calculating `element not in test_elements`. Default is False. |
| 788 | ``np.isin(a, b, invert=True)`` is equivalent to (but faster |
| 789 | than) ``np.invert(np.isin(a, b))``. |
| 790 | kind : {None, 'sort', 'table'}, optional |
| 791 | The algorithm to use. This will not affect the final result, |
| 792 | but will affect the speed and memory use. The default, None, |
| 793 | will select automatically based on memory considerations. |
| 794 | |
| 795 | * If 'sort', will use a mergesort-based approach. This will have |
| 796 | a memory usage of roughly 6 times the sum of the sizes of |
| 797 | `ar1` and `ar2`, not accounting for size of dtypes. |
| 798 | * If 'table', will use a lookup table approach similar |
| 799 | to a counting sort. This is only available for boolean and |
| 800 | integer arrays. This will have a memory usage of the |
| 801 | size of `ar1` plus the max-min value of `ar2`. `assume_unique` |
| 802 | has no effect when the 'table' option is used. |
| 803 | * If None, will automatically choose 'table' if |
| 804 | the required memory allocation is less than or equal to |
| 805 | 6 times the sum of the sizes of `ar1` and `ar2`, |
| 806 | otherwise will use 'sort'. This is done to not use |
| 807 | a large amount of memory by default, even though |
| 808 | 'table' may be faster in most cases. If 'table' is chosen, |
| 809 | `assume_unique` will have no effect. |
| 810 | |
| 811 | |
| 812 | Returns |
| 813 | ------- |
| 814 | isin : ndarray, bool |
| 815 | Has the same shape as `element`. The values `element[isin]` |
| 816 | are in `test_elements`. |
| 817 | |
| 818 | See Also |
| 819 | -------- |
| 820 | in1d : Flattened version of this function. |
| 821 | numpy.lib.arraysetops : Module with a number of other functions for |
| 822 | performing set operations on arrays. |
| 823 | |
| 824 | Notes |