API References

ismember.

Name : ismember.py Author : E.Taskesen Contact : erdogant@gmail.com github : https://github.com/erdogant/ismember Licence : See licences

ismember.ismember.is_row_in(a, b)

Calculates a in b, broadcasting over a only. Returns a boolean array that is True where a row of a is in b and False otherwise.

ismember.ismember.ismember(a_vec, b_vec, method=None)

Ismember: MATLAB equivalent function

Description

MATLAB equivalent ismember function [LIA, LOCB] = ISMEMBER(A,B) also returns an array LOCB containing the lowest absolute index in B for each element in A which is a member of B and 0 if there is no such index.

param a_vec:

type a_vec:

list or array

param b_vec:

type b_vec:

list or array

param method:

‘elementwise’: For each row, all elements are compared. ‘rows’: Row-wise matrice comparison.

type method:

[None, ‘rows’, ‘elementwise’] (default: None).

returns:
  • Iloc (np.ndarray) – Array containing logical 1 (true) where the data in A is found in B. Elsewhere, the array contains logical 0 (false)

  • idx (np.ndarray) – Array containing the lowest index in B for each value in A that is a member of B.

Examples

>>> a_vec = np.array([1,2,3])
>>> b_vec = np.array([4,1,2])
>>> Iloc, idx = ismember(a_vec,b_vec)
>>> Iloc
array([ True,  True, False])
>>> idx
array([1, 2])
>>> # Row wise comparison
>>> a_vec = np.array(((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12)))
>>> b_vec = np.array(((4, 5, 6), (7, 8, 0)))
>>> Iloc, idx = ismember(a_vec, b_vec, 'rows')
>>> idx
array([0])
>>> Iloc
array([False, True, False, False])

References