Last answered:

11 Feb 2021

Posted on:

06 Feb 2021


Confusion with return value of np.isin() method

Hi Team,

The new learning platform is awesome! Enjoying the new learning experience. Keep up the great work! :)

I have one question regarding the return value of np.isin() method. Lets say the result of the mentioned method is boolean True and I have stored it in a variable called result, When I display it, it shows


This is peculiar! This is neither an array (result[0] results in an error) nor a boolean value (type(result) shows numpy.ndarray).

However I can use it directly,

False & result

displays boolean False

So can you please explain what is array(True) and how to interpret it?

Thank you.

1 answers ( 0 marked as helpful)
Posted on:

11 Feb 2021


numpy.isin(element, test_elements, assume_unique=False, invert=False)
- Calculates element in test_elements, broadcasting over element only. Returns a boolean array of the same shape as an element that is True where an element of element is in test_elements and False otherwise.

Parameters: element: array_like
                     - Input array.

test_elements: array_like
                     - The values against which to test each value of an element. This argument is flattened if it is an array or                                         array_like.

assume_unique: bool, optional
                    - If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.

invert: bool, optional
                    - If True, the values in the returned array are inverted, as if calculating element not in test_elements. Default is                              false. np.isin(a, b, invert=True) is equivalent to (but faster than) np.invert(np.isin(a, b)).

Submit an answer