Skip to content Skip to sidebar Skip to footer

Check For Array - Is Value Contained In Another Array?

I'd like to return a boolean for each value in array A that indicates whether it's in array B. This should be a standard procedure I guess, but I can't find any information on how

Solution 1:

You can use in1d I believe -

np.in1d(A,B)

Solution 2:

For testing it without using numpy, try:

contained = [a in B for a in A]

result:

[False, False, True, True, True, False, False, True, False, False,
 False, True, True, True, False, False, False, True, False, False,
 True, True, True, False, False, True, True, False, False]

Post a Comment for "Check For Array - Is Value Contained In Another Array?"