What is ismember?

ismember is a Python library that checks whether the elements in X is present in Y. Or in other words, we can check if a particular element belongs to an array or not by using ismember() function. The result is in the form of logical 1 (True) or logical 0 (False).

Input

The input arrays can be one of the underneath types, and if the rows=True parameter is specified in the syntax, then the input arrays should have the same number of columns.

  • logical

  • numeric

  • character

  • string

  • datetime

  • categorical

Each of these input arrays can be in the form of:

  • Pandas DataFrame

  • Numpy Array

  • List

Output

Lx = ismember(X, Y) : This checks whether the elements in X is present in Y. If the elements are present, then it returns 1(True) else it returns 0(False). If X and Y are in the form of tables or timetables, then it returns the logical value for every row present and if X and Y are in the form of timetables, then row times are considered. The resultant value Lx is a column vector.

Lx = ismember (X, Y, "rows") : This syntax considers the rows of X and Y as single entities and determines the logical values which are in the form of 1 and 0. If the values are present, then it returns logical 1 (True) else it returns logical 0 (False). The rows option is not valid if cell arrays are used, provided that the input array is categorical or datetime array.

Lx, LocationY = ismember (____) : Here Location Y is used to find the lowest index values present in Y if the values present in X are a member of Y. If the value is 0, then it indicates that the elements present in X are not a part of Y. If there are rows option specified in the syntax, then LocationY contains the lowest index of Y, provided that rows in X should be a part of rows in Y. If the value is 0, then X is not in the row of Y. If X and Y are in the form of tables or timetables, then LocationY contains the lowest index of Y, provided that rows in X should be a part of rows in Y. If the value is 0, then X is not in the row of Y.

[1] https://www.datacamp.com/community/tutorials/pickle-python-tutorial