[Python-Dev] Accumulation module (original) (raw)
Kevin Jacobs jacobs at penguin.theopalgroup.com
Tue Jan 13 15:26:43 EST 2004
- Previous message: [Python-Dev] Accumulation module
- Next message: [Python-Dev] Accumulation module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 13 Jan 2004, Raymond Hettinger wrote:
* Is there a way to compute the standard deviation without multiple passes over the data (one to compute the mean and a second to sum the squares of the differences from the mean?
Yes --
def one_pass_stddev(l): n = 0 x = 0. xx = 0.
for y in l: n += 1 x += y xx += y*y
x /= n xx /= n var = max(0,xx - x*x) dev = var**0.5
return dev
Skewness and kurtosis can also be computed in one pass, though numerical stability problems can occur (even with std.dev) with these kinds of methods.
-Kevin
- Previous message: [Python-Dev] Accumulation module
- Next message: [Python-Dev] Accumulation module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]