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