After thinking it over, I did not go for
Robert or David's cool numpy tricks, but
I'll append a simple object in case someone
else wants to do more.
Cheers,
Alan Isaac
class EmpiricalCDF(object):
'''Empirical cdf.
First point will be (xmin,0).
Last point will be (xmax,1).
'''
def __init__(self, data, sortdata=True):
if sortdata:
data = N.sort(data)
self.data = data
self.nobs = len(data)
def gen_xp(self):
data, nobs = self.data, self.nobs
prob = N.linspace(0, 1, nobs+1)
xsteps = ( data[(idx)//2] for idx in xrange(2*nobs) )
psteps = ( prob[(idx+1)//2] for idx in xrange(2*nobs) )
return xsteps, psteps
def get_steps(self):
'''Return: 2tuple of arrays,
the data values and corresponding cumulative
probabilities.
'''
xsteps, psteps = self.gen_xp()
return N.fromiter(xsteps,'f'), N.fromiter(psteps,'f')
