title: Equivalent of `polyfit` for a 2D polynomial in Python
body: <p>I'd like to find a least-squares solution for the <code>a</code> coefficients in </p>
  
  <pre><code>z = (a0 + a1*x + a2*y + a3*x**2 + a4*x**2*y + a5*x**2*y**2 + a6*y**2 +
       a7*x*y**2 + a8*x*y)
  </code></pre>
  
  <p>given arrays <code>x</code>, <code>y</code>, and <code>z</code> of length 20. Basically I'm looking for the equivalent of <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html" rel="noreferrer"><code>numpy.polyfit</code></a> but for a 2D polynomial.</p>
  
  <p><a href="https://stackoverflow.com/questions/25440188/polyfit-for-two-variables">This question</a> is similar, but the solution is provided via MATLAB.</p>