stddev bug in util.py

T

Ted Nienstedt

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
(e-mail address removed)


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) )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,472
Latest member
blackwatermelon

Latest Threads

Top