Back
Can anyone have a more NumPy-like way of accomplishing this:
def uneven_compare(array1, array2): return numpy.all([numpy.any(array2 == elem) for elem in array1])
def uneven_compare(array1, array2):
return numpy.all([numpy.any(array2 == elem) for elem in array1])
I want to check if all of the elements in one array present in a second array.
You can use this:
In [6]: array1 = np.array([0, 1, 2, 5, 0])In [7]: array2 = np.array([0, 10, 20, 1, 2, 30, 5])In [8]: np.in1d(array1, array2)Out[8]: array([ True, True, True, True, True], dtype=bool)In [9]: np.all(np.in1d(array1, array2))Out[9]: True
In [6]: array1 = np.array([0, 1, 2, 5, 0])
In [7]: array2 = np.array([0, 10, 20, 1, 2, 30, 5])
In [8]: np.in1d(array1, array2)
Out[8]: array([ True, True, True, True, True], dtype=bool)
In [9]: np.all(np.in1d(array1, array2))
Out[9]: True
Learn Data Science with Python Course to improve your technical knowledge.
31k questions
32.8k answers
501 comments
693 users