2 Replies - 288 Views - Last Post: 06 November 2010 - 11:49 PM

#1 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

A program to find standard deviation

Posted 17 January 2009 - 04:51 PM

Description: You can calculate standard deviation of a given set of data
#A program to find standard deviation of given data
from math import *		#import math library
from Numeric import *		#import Numeric library (for array)
n=int(raw_input("Enter the number of class:"))	#Number of classes your data consists of
h=int(raw_input("Enter class interval:"))	#Class interval of your data
l=input("Enter Lower limit of first class:")
sum_f=0
sum_fmlu=0
total=0
array_a=zeros(n,Int)
array_b=zeros(n,Int)
for i in range(n):
	if i==0:
		l=l	#lower limit for first class
	else:
		l=l+h	#lower limit for other classes
	print "For class-%s"%(i+1)
	f=input("Frequency:")	#frequency of corresponding classes
	u=l+h			#upper limit of each class
	mean_ul=(l+u)/2.0	#mean of upper and lower limit
	fmean_ul=f*mean_ul	#multiplication of frequency and mean
	array_a[i]=mean_ul	#assigning mean to array
	array_b[i]=f		#assigning frequency to array
	sum_f=f+sum_f
	sum_fmlu=fmean_ul+sum_fmlu
x=sum_fmlu/sum_f		#arithmetic mean value
for i in range(n):
	diff=array_a[i]-x
	value=pow(diff,2)*array_b[i]
	total=value+total
std=sqrt(total/sum_f)		#standard deviation
print "The Standard Deviation is %f"%std



Is This A Good Question/Topic? 0
  • +

Replies To: A program to find standard deviation

#2 vidoushy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 07-November 10

Re: A program to find standard deviation

Posted 06 November 2010 - 11:49 PM

am getting an error while using numeric
Was This Post Helpful? 0
  • +
  • -

#3 vidoushy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 07-November 10

Re: A program to find standard deviation

Posted 06 November 2010 - 11:49 PM

am getting an error while using numeric
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1