If you are using NumPy (as in ludaavic's answer), for large arrays you'll probably want to use NumPy's sum
function rather than Python's builtin sum
for a significant speedup -- e.g., a >1000x speedup for 10 million element arrays on my laptop:
>>> import numpy as np
>>> ten_million = 10 * 1000 * 1000
>>> x, y = (np.random.randn(ten_million) for _ in range(2))
>>> %timeit sum(x > y) # time Python builtin sum function
1 loops, best of 3: 24.3 s per loop
>>> %timeit (x > y).sum() # wow, that was really slow! time NumPy sum method
10 loops, best of 3: 18.7 ms per loop
>>> %timeit np.sum(x > y) # time NumPy sum function
10 loops, best of 3: 18.8 ms per loop
(above uses IPython's %timeit
"magic" for timing)