I can't go too in-depth, but the reason it is slower is because sum(<array>)
is the built-in CPython sum function, whereas your <numpy array>.sum()
is using the numpy sum function, which is substantially faster than the built-in python version.
I imagine you would get similar results if you replaced sum(<array>)
with numpy.sum(<array>)
see numpy sum docs here: http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html