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: 2-tuple of arrays,
        the data values and corresponding cumulative 
        probabilities.
        '''
        xsteps, psteps = self.gen_xp()
        return N.fromiter(xsteps,'f'), N.fromiter(psteps,'f')




-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to