[SciPy-user] Vector mean calculation?
bob at redivi.com
Sat Apr 23 01:59:02 CDT 2005
On Apr 23, 2005, at 2:06 AM, Lance Boyle wrote:
> On Apr 22, 2005, at 3:04 AM, Fernando.Perez at colorado.edu wrote:
>> 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
>>>> effectively doing mod 2^31 arithmetic with negative wraparound).
>>> Why does Python allow modular arithmetic when the user doesn't
>>> 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
>> 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
>> (which are in many cases precisely what gives you speed). Life is
>> full of
> Well, I apologize for a bit of baiting. I get upset when a language
> lets me do something which I didn't intend, and when it is preventable
> in the design of the language. Python is 30 years newer than C but yet
> we have to put up with some of the same deficiencies of C (OK, so it
> was in a library). If the original poster was really suffering
> wrap-around (getting a mean value of a vector that is less than the
> minimum value), then he/she could be the poster boy/girl for poor
> language design. We might inquire about how much time he saved by
> using unchecked modular arithmetic versus how much time he wasted
> debugging his program, posting to this list, and making repairs. We
> might also ask him what might have been the consequences of getting
> such an incorrect result that he did not catch.
30 years in what universe? C has been around for about 34 years
(1971), and Python wasn't born yesterday (1990).
Anyway, you could ask him if he would prefer a default implementation
that ran 10x slower (probably worse) because it performed checked
arithmetic. You get one or the other, and both is simply more work.
If this function was 100% Python and didn't bother with Numeric/etc. it
would've done the right thing out of the box, but it might still be
More information about the SciPy-user