how to calculate standard deviation in python without any packages and functions except len(). And ensure the outcome is same as the output from r function sd().
Answer
Here is your python script ,if you have any doubt please comment, i am here to help you.
Here we know that, we can calculate the standard deviation as follows.
So here i will take one population [32,111,138,28,59,77,97], this standard deviation is 37.84501153334721.
So here i implemented the code for finding standard deviation without any package in python.
Here is the code
data = [32,111,138,28,59,77,97] #list of population
sum=0 #sum initially zero
length=len(data) #finding the length of population
for i in data:
sum=sum+i #total sum of the population
mean=sum/length #mean=total_sum/number of items
variance=0
for i in data:
variance=variance+((i-mean)**2/length) #finding variance
standard_deviation=variance**(1/2) #square root of the variance is SD.
print(str(standard_deviation))
output
Any doubt please comment ,
Thanks in advance
Get Answers For Free
Most questions answered within 1 hours.