Python 3 Statistics compute deviationSolutionimport statisti

Python 3 Statistics: compute deviation

Solution

import statistics #import the statistics package
A = [4,6,7,9,10,12] #A is the list of values
print(statistics.stdev(A)) #stdev from statistics package is the default method caluclates standard deviation.

\'\'\' below is the process without using statistics library. however, below is not efficient due to floating point precisions.\'\'\'


import math #import math
mean=sum(A)/float(len(A)) #caluclate mean
dev=math.sqrt(sum(pow(x-mean,2) for x in A)/float(len(A))) #caluclate deviation
print(dev)

Python 3 Statistics: compute deviationSolutionimport statistics #import the statistics package A = [4,6,7,9,10,12] #A is the list of values print(statistics.std

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site