[Numpy-discussion] dtype error in cumsum
Nikhil Padmanabhan
npadmana at Princeton.EDU
Mon Jul 3 16:35:40 EDT 2006
(I sent the following from my gmail account, but that does not seem
to have been accepted by sourceforge -- apologies in advance if it
shows up twice)
Hi,
(I saw some discussion of this on the mailing list, but was not sure
if there was a solution reached, so I thought I'd ask again....) If I
try to use cumsum on a numpy array with the dtype keyword, I get the
wrong answer if dtype does not match that of the array. More
specifically,
Python 2.4.3 (#1, Apr 3 2006, 18:07:18)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
->> import numpy
->> numpy.__version__
'0.9.9.2727'
->> a = numpy.arange(10002)
->> a.cumsum(dtype='f4')[-1]
0.0
->> a.cumsum(dtype='f8')[-1]
0.0
->> a.cumsum()[-1]
50015001
->> a.sum()
50015001
->> a.sum(dtype='f8')
50015001.0
Note that this only seems to affect cumsum(); sum() works just fine.
And cumsum works fine for small arrays....
Am I misunderstanding what the dtype keyword in cumsum is, or doing
something silly? I should not be overflowing any type bounds (I
think...)
This is with the SVN numpy, on an iBook G4 running OS X 10.4.6
Thanks in advance,
-- Nikhil
------------------------------------
Nikhil Padmanabhan
npadmana at princeton.edu
http://wwwphy.princeton.edu/~npadmana
nikhil@(609) 258-4355
More information about the NumPy-Discussion
mailing list