title: Python curve fit multiple parameters to multiple datasets
body: <p>I am trying to use scipy's curve_fit function to solve for model parameters.  I used <a href="https://stackoverflow.com/questions/28372597/python-curve-fit-with-multiple-independent-variables/28373422">Python curve_fit with multiple independent variables</a> as a starting point and was able to accomplish my needs, but now I'd like to use two input datasets to derive model parameters that would be shared by the two datasets (longer term I'd like to use many more than two data sets, but as a starting point I'm using two).</p>
  
  <p>I thought the easiest way to do this might be to use curve_fit and input my data as a matrix.  As a very contrived example I tried "augmenting" the example in the link above (I realize this isn't the prettiest code -- I'm just trying to get my bearings as to how I should actually be doing this).   </p>
  
  <pre><code>def func(X, a, b, c):
      x,y = X
      result0 = np.log(a) + b*np.log(x[0]) + c*np.log(y[0])
      result1 = np.log(a) + b*np.log(x[1]) + c*np.log(y[1])
      return np.array([result0, result1])
  
  # some artificially noisy data to fit
  x0 = np.linspace(0.1,1.1,101)
  y0 = np.linspace(1.,2., 101)
  
  x1 = np.linspace(0.1,1.1,101)
  y1 = np.linspace(1.,2., 101)
  
  a, b, c = 10., 4., 6.
  
  x = np.array([x0,x1])
  y = np.array([y0,y1])
  
  z = func((x,y), a, b, c)
  z[0] = z[0] * 1 + np.random.random(101)/100
  z[1] = z[1] * 1 + np.random.random(101)/100
  
  # initial guesses for a,b,c:
  p0 = 8., 2., 7.
  print curve_fit(func, (x,y), z, p0)
  </code></pre>
  
  <p>This script returns the following error:</p>
  
  <blockquote>
    <p>File "curveFitting.py", line 135, in 
        print curve_fit(func, (x,y), z, p0)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/optimize/minpack.py", line 533, in curve_fit
        res = leastsq(func, p0, args=args, full_output=1, **kw)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/optimize/minpack.py", line 371, in leastsq
        raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m))
    TypeError: Improper input: N=3 must not exceed M=2</p>
  </blockquote>
  
  <p>Am I trying to use curve_fit in a way that is unintended/inappropriate?  Is there another function/library I should be using instead?</p>