[SciPy-user] uint8 bug (Scipy core 0.4.1)

Travis Oliphant oliphant at ee.byu.edu
Tue Oct 18 14:55:58 CDT 2005

Jon Peirce wrote:

>Scipy arrays with dtype=uint8 or int8 seem to be 
>mathematically-challenged on my machine (AMD64 WinXP running python 
>2.4.2, scipy core 0.4.1). Simple int (and various others) appear fine.
> >>>import scipy
> >>>xx=scipy.array([100,100,100],scipy.int8)
> >>>print xx.sum()
> 44
> >>>xx=scipy.array([100,100,100],scipy.int)
> >>>print xx.sum()
> 300
This is not a bug.   In the first line, you are telling the computer to 
add up 8-bit integers.  The result does not fit in an 8-bit integer --- 
thus you are computing modulo 256.

I suspect you wanted for the first case.

xx.sum(rtype=int)  -- this will "reduce" using the long integer type on 
your platform.


More information about the SciPy-user mailing list