title: Doing many iterations of scipy's `curve_fit` in one go
body: <p>Consider the following MWE</p>
  
  <pre><code>import numpy as np
  from scipy.optimize import curve_fit
  X=np.arange(1,10,1)
  Y=abs(X+np.random.randn(15,9))
  
  def linear(x, a, b):
      return (x/b)**a
  
  coeffs=[]
  for ix in range(Y.shape[0]):
      print(ix)
      c0, pcov = curve_fit(linear, X, Y[ix])
      coeffs.append(c0)
  
  
  XX=np.tile(X, Y.shape[0])
  c0, pcov = curve_fit(linear, XX, Y.flatten())
  </code></pre>
  
  <p>I have a problem where I have to do basically that, but instead of 15 iterations it's thousands and it's pretty slow.</p>
  
  <p>Is there any way to do all of those iterations at once with <code>curve_fit</code>? I know the result from the function is supposed to be a 1D-array, so just passing the args like this</p>
  
  <pre><code>c0, pcov = curve_fit(nlinear, X, Y)
  </code></pre>
  
  <p>is not going to work. Also I think the answer has to be in flattening <code>Y</code>, so I can get a flattened result, but I just can't get anything to work.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I know that if I do something like</p>
  
  <pre><code>XX=np.tile(X, Y.shape[0])
  c0, pcov = curve_fit(nlinear, XX, Y.flatten())
  </code></pre>
  
  <p>then I get a "mean" value of the coefficients, but that's not what I want.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>For the record, I solved with using Jacques Kvam's set-up but implemented using Numpy (because of a limitation)</p>
  
  <pre><code>lX = np.log(X)
  lY = np.log(Y)
  A = np.vstack([lX, np.ones(len(lX))]).T
  m, c=np.linalg.lstsq(A, lY.T)[0]
  </code></pre>
  
  <p>And then <code>m</code> is <code>a</code> and to get <code>b</code>:</p>
  
  <pre><code>b=np.exp(-c/m)
  </code></pre>