I wrote a function to solve this that also handles multidimensional cases. (@ecatmur's answer works perfectly in two dimensions, but fails for 1D or 3D+)
import numpy as np
def haselement(arr,subarr):
'''Test if subarr is equal to one of the elements of arr.
This is the equivalent of the "in" operator when using lists instead of arrays.'''
arr = np.asarray(arr)
subarr = np.asarray(subarr)
if subarr.shape!=arr.shape[1:]:
return False
elif arr.ndim<2:
return (subarr==arr).any()
else:
boolArr = (subarr==arr)
boolArr.resize([arr.shape[0],np.prod(arr.shape[1:])])
return boolArr.all(axis=1).any()
tableau = np.array(range(10), dtype = np.uint8)
tableau.shape = (5,2)
haselement(tableau,[0,1])
1D is handled with an if statement, and ND is handled by resizing the array to 2D so that @ecatmur's algorithm will work. The other ways I thought of to solve this involved list comprehensions or loops (which could actually be more efficient but only if the list is long and the element is near the beginning); still, this seems more numpy-thonic.
You can also find the function here if you'd rather use it from a library:
https://github.com/davidmashburn/np_utils (obvious disclaimer, I am the author ;) )