So I have two arrays that look like below:
x1 = np.array([['a','b','c'],['d','a','b'],['c','a,c','c']])
x2 = np.array(['d','c','d'])
I want to check if each element in x2
exists in a corresponding column in x1
. So I tried:
print((x1==x2).any(axis=0))
#array([ True, False, False])
Note that x2[1] in x1[2,1] == True
. The problem is, sometimes an element we're looking for is inside an element in x1
(where it can be identified if we split by comma). So my desired output is:
array([ True, True, False])
Is there a way to do it using a numpy (or pandas) native method?