# Count elementwise matches for two NumPy arrays

Let’s say we have two integer NumPy arrays and want to count the number of elementwise matches.

Here are our two arrays (NumPy imported as `np`

):

To create a third (boolean) array that contains True for a match, and False otherwise, we can use the equality operator.

Given that, counting the number of matches is as easy as:

(Another option would be to use the (slower) `np.sum(a==b)`

)

## Leave a Comment