title: fitting multivariate curve_fit in python
body: <p>I'm trying to fit a simple function to two arrays of independent data in python. I understand that I need to bunch the data for my independent variables into one array, but something still seems to be wrong with the way I'm passing variables when I try to do the fit. (There are a couple previous posts related to this one, but they haven't been much help.)</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.optimize import curve_fit
  
  def fitFunc(x_3d, a, b, c, d):
      return a + b*x_3d[0,:] + c*x_3d[1,:] + d*x_3d[0,:]*x_3d[1,:]
  
  x_3d = np.array([[1,2,3],[4,5,6]])
  
  p0 = [5.11, 3.9, 5.3, 2]
  
  fitParams, fitCovariances = curve_fit(fitFunc, x_3d[:2,:], x_3d[2,:], p0)
  print ' fit coefficients:\n', fitParams
  </code></pre>
  
  <p>The error I get reads, </p>
  
  <pre><code>raise TypeError('Improper input: N=%s must not exceed M=%s' % (n, m)) 
  TypeError: Improper input: N=4 must not exceed M=3
  </code></pre>
  
  <p>What is <code>M</code> the length of? Is <code>N</code> the length of <code>p0</code>? What am I doing wrong here?</p>