[SciPy-user] Vector mean calculation?

Fernando.Perez at colorado.edu Fernando.Perez at colorado.edu
Fri Apr 22 05:04:00 CDT 2005

Lance Boyle wrote:
> On Apr 21, 2005, at 5:41 PM, Fernando.Perez at colorado.edu wrote:
>>Quoting Thomas Davidoff <davidoff at haas.berkeley.edu>:
>>>I have a vector with min equal to 412.  Why am I getting a negative
>>Without more details, it's quite difficult to be sure.  Most likely,
>>it's very long and of integer type (ints are 32 bit objects, so you are
>>effectively doing mod 2^31 arithmetic with negative wraparound).
> Why does Python allow modular arithmetic when the user doesn't request
> modular arithmetic?

Well, it's just what happens in C always: regular ints are 32 bit objects, hence
with a range of [-2**31,2**31-1].  If you start adding and go beyond the right
endpoint of the interval, it will wrap around the left.  Pure python shields
you from this with silent promotion to  python longs, which are
arbitrary-length integers.  But in Numeric/numarray, you are using raw C
objects (for speed reasons), so you can't escape some of their limitations
(which are in many cases precisely what gives you speed).   Life is full of



More information about the SciPy-user mailing list