Q. Standard deviation. The standard deviation can be done a few ways but we will use the formula shown below. This computes a deviation measurement as the square of the difference between each element and the mean.

Q 12 type C ||  Dictionaries  || Sumita arora || class 11|| computer science
Q 12 type C ||  Dictionaries  || Sumita arora || class 11|| computer science


Write a program to compute the standard deviation for the numeric samples collected in a tuple namely samples.


Answer =
import math

tup = eval  (input("Enter the numeric tupal "))
n = len (tup)
sum = 0
lst = []

for i in range (n):
        sum = sum + tup[i]

mean = sum /n
print ("mean ",mean)

for i in range (n):
        lst.insert(i,tup[i]-mean)

print ("List ",lst)
square = []

for i in range (n):
        square.insert(i,lst[i]*lst[i])
        sum = sum + lst [i] * lst[i]

print ("Square of each element ",square)

s = math.sqrt (sum/(n-1))
print ("Stantard daviation ",s)

Output :-

Enter the numeric tupal (5,9,15,16,19,28,36,38)
mean  20.75
List  [-15.75, -11.75, -5.75, -4.75, -1.75, 7.25, 15.25, 17.25]
Square of each element  [248.0625, 138.0625, 33.0625, 22.5625, 3.0625, 52.5625, 232.5625, 297.5625]
Stantard daviation  13.057564857200596

>>>


2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post