The problem appears to be that one of the numbers in your data, is bigger than the max np.float64
accepts. If you run, np.finfo(np.float64)
, you'll see the biggest number this dtype accepts:
Machine parameters for float64
---------------------------------------------------------------
precision = 15 resolution = 1.0000000000000001e-15
machep = -52 eps = 2.2204460492503131e-16
negep = -53 epsneg = 1.1102230246251565e-16
minexp = -1022 tiny = 2.2250738585072014e-308
maxexp = 1024 max = 1.7976931348623157e+308
nexp = 11 min = -max
--------------------------------------------------------------
According to this answer: https://stackoverflow.com/a/37272717/4014051 python objects use an arbitrary length implementation, therefore the solution would be to make the dtype of your array object
. This means that your code will be slower overall, as your data are not numpy objects, but presumably it will output the correct sum.