Hello everyone,
here is my problem: I would like to create a boolean matrix B that contains True
everywhere that matrix A has a value contained in vector v. One inconvenient solution would be:
import numpy as np
>>> A = np.array([[0,1,2], [1,2,3], [2,3,4]])
array([[0, 1, 2],
[1, 2, 3],
[2, 3, 4]])
>>> v = [1,2]
>>> B = (A==v[0]) + (A==v[1]) # matlab: ``B = ismember(A,v)``
array([[False, True, True],
[ True, True, False],
[ True, False, False]], dtype=bool)
Is there maybe a solution that would be more convenient if A and v would have more values?
Cheers!