title: Python nonlinear regression error using curve_fit
body: <p>I'm trying to obtain 3 unknown parameters of a function using <code>scipy.optimize.curve_fit</code>. I took the example code from the Scipy documentation found here : <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow noreferrer">https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html</a></p>
  
  <p>I use simple data and plot it : </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.optimize import curve_fit
  
  xdata = np.array([4.2, 8.5, 10.3, 17.2, 20.7, 38.2, 75.6, 850, 1550])     
  ydata = np.array([83.3, 53.3, 44.8, 32.6, 28.1, 19.5, 11.5, 5.7, 5.3]) 
  
  plt.plot(xdata, ydata, 'b-', label='data')
  </code></pre>
  
  <p>And this is the function and the rest of the code : </p>
  
  <pre><code>def func(x, a, b, c):
      return x*(a*(1-m.exp(-b/x))+c*m.exp(-b/x))-x*c
  
  popt, pcov = curve_fit(func, xdata, ydata)
  popt
  
  plt.plot(xdata, func(xdata, *popt), 'r-',
           label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
  popt, pcov = curve_fit(func, xdata, ydata, bounds=(0, [3., 1., 0.5]))
  popt
  
  plt.plot(xdata, func(xdata, *popt), 'g--',
           label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
  
  plt.xlabel('x')
  plt.ylabel('y')
  plt.legend()
  plt.show()
  </code></pre>
  
  <p>I get the error below. </p>
  
  <p><code>TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'</code></p>
  
  <p>And after all the error details :</p>
  
  <p><code>error: Result from function call is not a proper array of floats.</code></p>
  
  <p>I tried  <code>xdata = np.array( ... , dtype='float64')</code>, and tried all solutions proposed on this thread with no success : <a href="https://stackoverflow.com/questions/39452792/cannot-cast-array-data-from-dtypeo-to-dtypefloat64">Cannot cast array data from dtype(&#39;O&#39;) to dtype(&#39;float64&#39;)</a></p>
  
  <p>Any advice and ideas to make this regression work ?</p>