Created
February 21, 2013 12:52
-
-
Save mushfiq/5004545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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