stddev bug in util.py
Ted Nienstedt
tnienstedt at telesyn.com
Thu Dec 4 11:04:37 EST 2003
Gentlemen, et al:
The stddev function in the current, as of 11/03, utils.py module has a
bug. Corrected code excerpt below, in red; comments in blue.
Ted Nienstedt
tnienstedt at telesyn.com
def mean(values):
"""Return the arithmetic average of the values."""
return sum(values) / float(len(values))
def stddev(values, meanval=None):
"""The standard deviation of a set of values.
Pass in the mean if you already know it."""
if meanval == None: meanval = mean(values)
#return math.sqrt( sum([(x - meanval)**2 for x in values]))
# the above was missing the crucial divide by n-1 !
return math.sqrt( sum([(x - meanval)**2 for x in values]) /
(len(values)-1) )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031204/3bc98148/attachment.html>
More information about the Python-list
mailing list