title: scipy.optimize.curvefit() - array must not contain infs or NaNs
body: <p>I am trying to fit some data to a curve in Python using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="noreferrer"><code>scipy.optimize.curve_fit</code></a>.  I am running into the error <code>ValueError: array must not contain infs or NaNs</code>.</p>
  <p>I don't believe either my <code>x</code> or <code>y</code> data contain infs or NaNs:</p>
  <pre><code>&gt;&gt;&gt; x_array = np.asarray_chkfinite(x_array)
  &gt;&gt;&gt; y_array = np.asarray_chkfinite(y_array)
  &gt;&gt;&gt;
  </code></pre>
  <p>To give some idea of what my <code>x_array</code> and <code>y_array</code> look like at either end (<code>x_array</code> is counts and <code>y_array</code> is quantiles):</p>
  <pre><code>&gt;&gt;&gt; type(x_array)
  &lt;type 'numpy.ndarray'&gt;
  &gt;&gt;&gt; type(y_array)
  &lt;type 'numpy.ndarray'&gt;
  &gt;&gt;&gt; x_array[:5]
  array([0, 0, 0, 0, 0])
  &gt;&gt;&gt; x_array[-5:]
  array([2919, 2965, 3154, 3218, 3461])
  &gt;&gt;&gt; y_array[:5]
  array([ 0.9999582,  0.9999163,  0.9998745,  0.9998326,  0.9997908])
  &gt;&gt;&gt; y_array[-5:]
  array([  1.67399000e-04,   1.25549300e-04,   8.36995200e-05,
       4.18497600e-05,  -2.22044600e-16])
  </code></pre>
  <p>And my function:</p>
  <pre><code>&gt;&gt;&gt; def func(x,alpha,beta,b):
  ...    return ((x/1)**(-alpha) * ((x+1*b)/(1+1*b))**(alpha-beta))
  ...
  </code></pre>
  <p>Which I am executing with:</p>
  <pre><code>&gt;&gt;&gt; popt, pcov = curve_fit(func, x_array, y_array)
  </code></pre>
  <p>resulting in the error stack trace:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py&quot;, line 426, in curve_fit
  res = leastsq(func, p0, args=args, full_output=1, **kw)
  File &quot;/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py&quot;, line 338, in leastsq
  cov_x = inv(dot(transpose(R),R))
  File &quot;/usr/lib/python2.7/dist-packages/scipy/linalg/basic.py&quot;, line 285, in inv
  a1 = asarray_chkfinite(a)
  File &quot;/usr/lib/python2.7/dist-packages/numpy/lib/function_base.py&quot;, line 590, in asarray_chkfinite
  &quot;array must not contain infs or NaNs&quot;)
  ValueError: array must not contain infs or NaNs
  </code></pre>
  <p>I'm <em>guessing</em> the error might not be with respect to my arrays, but rather an array created by scipy in an intermediate step?  I've had a bit of a dig through the relevant scipy source
  files, but things get hairy pretty quickly debugging the problem that way.  Is there something obvious I'm doing wrong here?  I've seen casually mentioned in other questions that sometimes certain initial parameter guesses (of which I currently don't have any explicit) might result in these kind of errors, but even if this is the case, it would be good to know <code>a)</code> why that is and <code>b)</code> how to avoid it.</p>