[Numpy-discussion] dtype conversion errors in cumsum

Nikhil Padmanabhan nikhil.padmanabhan at gmail.com
Mon Jul 3 13:47:55 CDT 2006


Hi,

(I saw some discussion of this on the mailing list, but was not sure  
if there was a solution reached...) 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
nikhil.padmanabhan at gmail.com







More information about the Numpy-discussion mailing list