# L-4 MCS 275 Wed 20 Jan 2010 : class Histogram class Histogram: """ a frequency table collects simulation results """ def __init__(self,n): """ initializes frequency table with n bins for processing data points in [0,1] """ self.T = map(lambda i:0, range(0,n)) def add(self,x): "adds a point to the table" n = len(self.T) ind = int(n*x) # first digit of x self.T[ind] = self.T[ind] + 1 def __str__(self): "returns the string representation" return str(self.T) def __repr__(self): "defines the representation of the histogram" return str(self.T)