0 Replies - 137 Views - Last Post: 27 January 2009 - 10:28 AM

#1 atik97   User is offline

  • ???
  • member icon

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

A Program to find the mode of given data

Posted 27 January 2009 - 10:28 AM

Description: It will calculate the mode of given data set.
from Numeric import *
n=int(input("Enter the number of class:"))
f=zeros(n+1,Int)      #creating empty array
lw=zeros(n,Float)    #creating empty array
h=int(input("Enter class interval:"))
for i in range(n):
    print "For class %s"%(i+1)
    l=int(input("Lower limit:"))
    a=int(input("Frequency:"))
    lw[i]=l
    f[i]=a
for i in range(n):
    #finds which is the modal class
    if i==0:
        hf=f[i]
        j=1
    else:
        if hf>f[i]:
            hf=hf
            j=1
        else:
            hf=f[i]
            j=i

mode=lw[j]+((f[j]-f[j-1])*h/(2*(f[j])-f[j-1]-f[j+1]))

print "The mode of the given data is %s"%mode


Is This A Good Question/Topic? 0
  • +

Page 1 of 1