Commit 60a05ec2 authored by unknown's avatar unknown

Histogram class and test added

parent 2c1bcb75
class Histogram:
def __init__(self, bins, min, max):
self.bins = [0] * bins
self.min = min
self.max = max
def add(self, number):
bin_index = self.get_bin_index(number)
self.bins[bin_index] += 1
def remove(self, number):
bin_index = self.get_bin_index(number)
self.bins[bin_index] -= 1
def get_bin_index(self, number):
return (number - self.min) / ((self.max - self.min) / len(self.bins))
\ No newline at end of file
from Histogram import Histogram
his = Histogram(10, 10, 110)
his.add(10)
his.add(19)
his.add(20)
his.add(29)
his.add(30)
his.add(39)
his.add(40)
his.add(49)
his.add(50)
his.add(59)
his.add(60)
his.add(69)
his.add(70)
his.add(79)
his.add(80)
his.add(89)
his.add(90)
his.add(99)
his.add(100)
his.add(109)
print his.bins
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment