check how many elements are equal in two numpy arrays python
Using numpy.sum
:
>>> import numpy as np
>>> a = np.array([1, 2, 3, 4])
>>> b = np.array([1, 2, 4, 3])
>>> np.sum(a == b)
2
>>> (a == b).sum()
2
As long as both arrays are guaranteed to have the same length, you can do it with:
np.count_nonzero(A==B)