[Bug] important bug in method sum
Hello, when doing some test I saw a very important bug in numpy (at least on the svn version and 1.0.3 (ubuntu package)). I'm using a svn version of numpy: In [31]: numpy.__version__ Out[31]: '1.0.5.dev4767' The problem is for an array larger than 256*256 the sum is going crazy. In [45]: numpy.arange(256*256) Out[45]: array([ 0, 1, 2, ..., 65533, 65534, 65535]) In [46]: numpy.arange(256*256).sum() Out[46]: 2147450880 In [47]: numpy.arange(257*257) Out[47]: array([ 0, 1, 2, ..., 66046, 66047, 66048]) In [48]: numpy.arange(257*257).sum() Out[48]: -2113765120
import numpy numpy.arange(256*256).sum() 2147450880 numpy.arange(257*257).sum() -2113765120 numpy.__version__ '1.0.3'
Sorry for this bad news. N. ps: my system is an ubuntu linux 32
On Feb 5, 2008 11:58 AM, <humufr@yahoo.fr> wrote:
The problem is for an array larger than 256*256 the sum is going crazy.
In [45]: numpy.arange(256*256) Out[45]: array([ 0, 1, 2, ..., 65533, 65534, 65535])
In [46]: numpy.arange(256*256).sum() Out[46]: 2147450880
In [47]: numpy.arange(257*257) Out[47]: array([ 0, 1, 2, ..., 66046, 66047, 66048])
In [48]: numpy.arange(257*257).sum() Out[48]: -2113765120
You hit the limit on how big an integer can be. You'll have to switch to floats to do the sum:
numpy.arange(257*257, dtype=numpy.float64).sum() 2181202176.0
On Feb 5, 2008 9:27 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
On Feb 5, 2008 11:58 AM, <humufr@yahoo.fr> wrote:
The problem is for an array larger than 256*256 the sum is going crazy.
In [45]: numpy.arange(256*256) Out[45]: array([ 0, 1, 2, ..., 65533, 65534, 65535])
In [46]: numpy.arange(256*256).sum() Out[46]: 2147450880
In [47]: numpy.arange(257*257) Out[47]: array([ 0, 1, 2, ..., 66046, 66047, 66048])
In [48]: numpy.arange(257*257).sum() Out[48]: -2113765120
You hit the limit on how big an integer can be. You'll have to switch to floats to do the sum:
numpy.arange(257*257, dtype=numpy.float64).sum() 2181202176.0
Or tell numpy to use float64 for the sum: In [6]: a = arange(257*257) In [7]: a.sum(dtype=float64) Out[7]: 2181202176.0 Chuck
participants (3)
-
Charles R Harris -
humufr@yahoo.fr -
Keith Goodman