[Tutor] Summing arrays
Peter Otten
__peter__ at web.de
Thu Mar 16 06:10:11 EDT 2017
Peter Otten wrote:
> (Specifying dtype=float forces floating point arithmetic which is inexact)
I found a way to avoid the error:
>>> import numpy as np
>>> def sum2(N):
... a = np.arange(1, N+1, dtype=object)
... return (2*(1+3**(a-1))).sum()
...
>>> sum2(50)
717897987691852588770348
As this operates on int objects rather than C/machine language numbers this
will probably be significantly slower than dtype=int or dtype=float.
More information about the Tutor
mailing list