[Python-ideas] math.fsum: summing multiple running sums at once

Mark Dickinson dickinsm at gmail.com
Thu Apr 29 11:54:11 CEST 2010


On Tue, Apr 27, 2010 at 6:55 PM, Ilya Shlyakhter <ilya_shl at alum.mit.edu> wrote:
> A suggestion: extend math.fsum to accept an iterable that yields
> tuples of floats, and returns a tuple of sums.
> This would permit summing multiple running sums at once (e.g. keeping
> both a sum and a sum-of-squares for computing
> standard deviation from an iterable), or summing a stream of complex numbers.
>
> An alternative would be to make an object-oriented version of fsum
> that has a method for adding a number to the sum;
> then an array of such objects could be used to sum multiple iterables
> simultaneously.

It's an interesting idea.  The second alternative appeals to me more
than the first:  I could see other uses for being able to pass a
partial sum state around.

Mark



More information about the Python-ideas mailing list