En Mon, 05 May 2008 05:08:15 -0300, Raymond Hettinger <[EMAIL PROTECTED]>
escribió:
On May 3, 9:50 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
I did the following calculation: Generated a list of a million random
numbers between 0 and 1, constructed a new list by subtracting the mean
valu
En Mon, 05 May 2008 11:08:02 -0300, Szabolcs <[EMAIL PROTECTED]> escribió:
On May 5, 12:24 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
Szabolcs <[EMAIL PROTECTED]> wrote:
> On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>> Gabriel Genellina wrote:
>> > Python doesn't require __a
Gabriel Genellina wrote:
Python doesn't require __add__ to be associative, so this should not be used as
a general sum replacement. But if you know that you're adding floating point
numbers you can use whatever algorithm best fits you. Or use numpy arrays; I
think they implement Kahan summatio
On May 3, 4:31 pm, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> wrote:
> On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
> > On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
>
> > > Arnaud Delobelle wrote:
>
> > >> sum() works for any sequence of objects with an __add__ method, not
>
On May 5, 12:24 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Szabolcs <[EMAIL PROTECTED]> wrote:
> > On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> >> Gabriel Genellina wrote:
>
> >> > Python doesn't require __add__ to be associative, so this should
> >> > not be
> > used as a gen
Szabolcs <[EMAIL PROTECTED]> wrote:
> On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>> Gabriel Genellina wrote:
>>
>> > Python doesn't require __add__ to be associative, so this should
>> > not be
> used as a general sum replacement.
>>
>> It does not _require_ this, but using an
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Sun, 04 May 2008 12:58:25 -0300, Duncan Booth
> <[EMAIL PROTECTED]> escribió:
>
>> Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>>
>>> I thought that it would be very nice if the built-in sum() function
>>> used this algorithm by default. Has th
On May 5, 9:37 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> Gabriel Genellina wrote:
>
> > Python doesn't require __add__ to be associative, so this should not be
> > used as a general sum replacement.
>
> It does not _require_ this, but using an __add__ that is not commutative
> and associati
> > > However I find the seccond argument hack ugly. Does the sum way have any
> > > performance advantages over the reduce way?
>
> > Yes, sum() is faster:
...
> Not really; you measure the import and the attribute access time in
> the second case. sum() is 2x faster for adding numbers only:
Try
On May 3, 9:50 am, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> I did the following calculation: Generated a list of a million random
> numbers between 0 and 1, constructed a new list by subtracting the mean
> value from each number, and then calculated the mean again.
>
> The result should be 0,
Gabriel Genellina wrote:
Python doesn't require __add__ to be associative, so this should not be used as
a general sum replacement.
It does not _require_ this, but using an __add__ that is not commutative
and associative, or has side effects, would qualify as a serious misuse,
anyway. So I
Duncan Booth wrote:
Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
I thought that it would be very nice if the built-in sum() function used
this algorithm by default. Has this been brought up before? Would this
have any disadvantages (apart from a slight performance impact, but
Python is a high
En Sun, 04 May 2008 12:58:25 -0300, Duncan Booth <[EMAIL PROTECTED]> escribió:
> Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
>
>> I thought that it would be very nice if the built-in sum() function used
>> this algorithm by default. Has this been brought up before? Would this
>> have any disadvan
Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> I thought that it would be very nice if the built-in sum() function used
> this algorithm by default. Has this been brought up before? Would this
> have any disadvantages (apart from a slight performance impact, but
> Python is a high-level languag
On May 3, 7:05 pm, sturlamolden <[EMAIL PROTECTED]> wrote:
> On May 3, 10:13 pm, hdante <[EMAIL PROTECTED]> wrote:
>
> > I believe that moving this to third party could be better. What about
> > numpy ? Doesn't it already have something similar ?
>
> Yes, Kahan summation makes sence for numpy arra
On Sat, 03 May 2008 17:43:57 -0700, George Sakkis wrote:
> On May 3, 7:12 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
>> On Sun, 04 May 2008 00:31:01 +0200, Thomas Dybdahl Ahle wrote:
>> > On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
>> >> On Sat, 03 May 2008 20:44:19 +0200, Szabol
On Sun, 04 May 2008 00:31:01 +0200, Thomas Dybdahl Ahle wrote:
> On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
>> On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
>>
>> > Arnaud Delobelle wrote:
>> >>
>> >> sum() works for any sequence of objects with an __add__ method, not
On May 3, 7:12 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
> On Sun, 04 May 2008 00:31:01 +0200, Thomas Dybdahl Ahle wrote:
> > On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
> >> On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
>
> >> > Arnaud Delobelle wrote:
>
> >> >> sum
On Sat, 2008-05-03 at 21:37 +, Ivan Illarionov wrote:
> On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
>
> > Arnaud Delobelle wrote:
> >>
> >> sum() works for any sequence of objects with an __add__ method, not
> >> just floats! Your algorithm is specific to floats.
> >
> > Thi
On May 3, 10:13 pm, hdante <[EMAIL PROTECTED]> wrote:
> I believe that moving this to third party could be better. What about
> numpy ? Doesn't it already have something similar ?
Yes, Kahan summation makes sence for numpy arrays. But the problem
with this algorithm is optimizing compilers. The
On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
> Arnaud Delobelle wrote:
>>
>> sum() works for any sequence of objects with an __add__ method, not
>> just floats! Your algorithm is specific to floats.
>
> This occurred to me also, but then I tried
>
> sum(['abc', 'efg'], '')
Inter
Torsten Bronger wrote:
No, the above expression should yield ''+'abc'+'efg', look for the
signature of sum in the docs.
You're absolutely right, I misread it. Sorry about that.
--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && A
Hallöchen!
Erik Max Francis writes:
> Szabolcs Horvát wrote:
>
>> Arnaud Delobelle wrote:
>>>
>>> sum() works for any sequence of objects with an __add__ method, not
>>> just floats! Your algorithm is specific to floats.
>>
>> This occurred to me also, but then I tried
>>
>> sum(['abc', 'efg'],
Szabolcs Horvát wrote:
Arnaud Delobelle wrote:
sum() works for any sequence of objects with an __add__ method, not
just floats! Your algorithm is specific to floats.
This occurred to me also, but then I tried
sum(['abc', 'efg'], '')
and it did not work. Or is this just a special exceptio
Szabolcs Horvát <[EMAIL PROTECTED]> writes:
> Arnaud Delobelle wrote:
>>
>> sum() works for any sequence of objects with an __add__ method, not
>> just floats! Your algorithm is specific to floats.
>
> This occurred to me also, but then I tried
>
> sum(['abc', 'efg'], '')
>
> and it did not work.
On May 3, 3:44 pm, Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
>
> > sum() works for any sequence of objects with an __add__ method, not
> > just floats! Your algorithm is specific to floats.
>
> This occurred to me also, but then I tried
>
> sum(['abc', 'efg'], '')
>
> an
Arnaud Delobelle wrote:
sum() works for any sequence of objects with an __add__ method, not
just floats! Your algorithm is specific to floats.
This occurred to me also, but then I tried
sum(['abc', 'efg'], '')
and it did not work. Or is this just a special exception to prevent the
misuse
Szabolcs Horvát <[EMAIL PROTECTED]> wrote:
> I did the following calculation: Generated a list of a million random
> numbers between 0 and 1, constructed a new list by subtracting the mean
> value from each number, and then calculated the mean again.
>
> The result should be 0, but of cours
On Sat, 03 May 2008 18:50:34 +0200, Szabolcs Horvát wrote:
> I did the following calculation: Generated a list of a million random
> numbers between 0 and 1, constructed a new list by subtracting the mean
> value from each number, and then calculated the mean again.
>
> The result should be 0, b
Szabolcs Horvát <[EMAIL PROTECTED]> writes:
[...]
> A little research shows that Mathematica uses a "compensated
> summation" algorithm. Indeed, using the algorithm described at
> http://en.wikipedia.org/wiki/Kahan_summation_algorithm
> gives us a result around ~ 10^-17:
>
> def compSum(arr):
>
I did the following calculation: Generated a list of a million random
numbers between 0 and 1, constructed a new list by subtracting the mean
value from each number, and then calculated the mean again.
The result should be 0, but of course it will differ from 0 slightly
because of rounding
31 matches
Mail list logo