Skip to content

Instantly share code, notes, and snippets.

@mushfiq
Created February 21, 2013 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mushfiq/5004545 to your computer and use it in GitHub Desktop.
Save mushfiq/5004545 to your computer and use it in GitHub Desktop.
from __future__ import division
from math import sqrt, pow
class StandardDeviation(object):
def do_round(self, data):
data = "%.3f" % round(data, 3)
return float(data)
def do_diff(self, n, mean):
return pow((n-mean), 2)
def standDev(self, data_list):
mean = sum(data_list)/len(data_list)
result = sqrt(sum([self.do_diff(s, mean) for s in \
data_list] )/len(data_list))
return float(self.do_round(result))
if __name__=='__main__':
data_list = [2, 4, 4, 4, 5, 5, 7, 9 ]
std = StandardDeviation()
print std.standDev(data_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment