1

Does 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])

I just want to check if all of the elements in one array exist in a second array.

Thanks :)

0

1 Answer 1

1

Use numpy.in1d :

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.