[SciPy-User] Vectorizing scipy.optimize.curve_fit

Paul Hobson pmhobson@gmail....
Fri Feb 1 17:07:52 CST 2013

Hey folks,

I've run  into a bit of a roadblock. I've got some model runs (x) in an Nx2
array where the first column is the input, and the second column is the
output. So in a single case, I'd do:

popt, pcov = scipy.optimize.curve_fit(myFit, x[:,0], x[:,1])

But how should I handle, say, 5000 model runs such that x.shape = (500, N,
2) and I want the 5000 results for popt?

This works:
popt_array = np.empty(5000, 2)
for r, layer in enumerate(model_runs):
    popt, pcov = scipy.optimize.curve_fit(myFit, layer[:,0] layer[:,1])
    popt_array[r] = popt

But is there a better (faster way)? The number of model runs and data
points may grow sustatially (~10^4 runs and 10^3 data points).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130201/3fffcd0d/attachment-0001.html 

More information about the SciPy-User mailing list