import pylab import scipy.stats as ss nrm = ss.norm nx = nrm.pdf # Lookup table based implementations ------------------------------------------ def init_nx_table(xlim=5,N=1001): """Go from -xlim to +xlim and make N entries, return us the dx and x0. if N is made odd it is better""" idx0 = int(N/2) tbl = pylab.zeros(N) x = pylab.linspace(-xlim,xlim,N) dx = x[1] - x[0] tbl = nx(x) return x, tbl, idx0, dx def nx_lookup(x,mu,tbl, idx0, dx): """x needs to be an array.""" sz = tbl.size ret = pylab.zeros(x.size) #Our results idx = (x-mu)/dx + idx0 + .5 #indexes into our table need +.5 because of rounding idxidx = pylab.find((idx>=0) & (idx