Observe in the following code, creating an numpy array and calling the builtin python sum
function produces different results than numpy.sum
How is numpy’s sum function implemented? And why is the result different?
test = [.1]*10
test = [np.float64(x) for x in test]
test[5]= np.float64(-.9)
d = [np.asarray(test) for x in range(0,60000)]
sum(sum(d))
outputs
np.float64(-1.7473212210461497e-08)
but
np.sum(d)
outputs
np.float64(9.987344284922983e-12)
3