Something along the lines of:
>>> a = np.array([1, 2, 3, 5, 5, 6, 7]) >>> b = np.array([1, 2, 3, 4, 5, 6, 7]) >>> (a != b).sum()/float(a.size) 0.14285714285714285
Refresh . I am wondering why this is a little faster:
a = np.random.randint(4, size=1000) b = np.random.randint(4, size=1000) timeit('from __main__ import a, b; (a != b).sum()/float(a.size)', number=10000)
source share