+ 1

Standard deviation (Python)

How can I define a function for calculating standard deviation without using functions imported from the math module?

14th Nov 2016, 3:16 PM
Thamsanca Ephraim Mnune
Thamsanca Ephraim Mnune - avatar
1 Odpowiedź
+ 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))
14th Nov 2016, 9:11 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar