Python 3 Script to Calculate Standard Deviance of an Array Using stdev() and variance() Function in Math Module Full Project For Beginners

 

 

import math

def variance(data, ddof=0):
     n = len(data)
     mean = sum(data) / n
     return sum((x - mean) ** 2 for x in data) / (n - ddof)

 def stdev(data):
       var = variance(data)
       std_dev = math.sqrt(var)
       return std_dev

stdev([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])

 

 

Using Python’s pstdev() and stdev()

 

 

>>> import statistics

>>> statistics.pstdev([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])
2.4000000000000004

>>> statistics.stdev([4, 8, 6, 5, 3, 2, 8, 9, 2, 5])
2.5298221281347035

Leave a Reply