0

I have two arrays with different size

a = np.array([[5, 0], [2, 4], [0, 1], [3, 4], [1, 5], [5, 6], [7, 9]])
b = np.array([[0, 3], [5, 6], [2, 5], [2, 4]])

I need

c = np.array([False, True, False, False, False, True, False])

i.e. array 'b' have rows [5, 6] and [2, 4] in array 'a'. Currently, I do this by

logical = np.zeros(a.shape[0]).astype(bool)
for i in range(b.shape[0]):
    logical += np.all(a == b[i], axis=1)

Is there any numpy code for doing this?

0

1 Answer 1

3

Let's try broadcasting:

(a[None,:] == b[:,None]).all(-1).any(0)

Output:

array([False,  True, False, False, False,  True, False])
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.