+ 1
Standard deviation (Python)
How can I define a function for calculating standard deviation without using functions imported from the math module?
1 Answer
+ 5
Just do not use the functions from the math library. Instead of the Math.sqrt(x) function, use x**(0.5).
def standard_deviation(List):
avg = sum(List) * 1.0 / len(List)
variance = list( map( lambda x: (x - avg)**2, List) )
return ( sum(variance) * 1.0 / len(variance) ) ** 0.5
s = [2,4,4,4,5,5,7,9]
print (standard_deviation(s))