I have been trying to optimize this code:

```
def spectra(mE, a):
    pdf = lambda E: np.exp(-(a+1)*E/mE)*(((a+1)*E/mE)**(a+1))/(scipy.special.gamma(a+1)*E)
    u=[]
    n=np.random.uniform()
    E=np.arange(0.01,150, 0.1)
    for i in E: 
        u.append(scipy.integrate.quad(pdf,0,i)[0])

    f=interp1d(u, E)
    return f(n)

```

I was trying to create a lookup table out of `f`, but it appears that every time I call the function it does the integration all over again. Is there a way to put in something like an if statement, which will let me create `f` once for values of `mE` and `a` and then just call that afterwards?

Thanks for the help.

Cheers.