Cannot cast array data from dtype('O') to dtype('float64')
<p>I am using scipy's curve_fit to fit a function to some data, and receive the following error;</p>

<pre><code>Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
</code></pre>

<p>which points me to this line in my code;</p>

<pre><code>popt_r, pcov = curve_fit(
                    self.rightFunc, np.array(wavelength)[beg:end][edgeIndex+30:], 
                    np.dstack(transmitted[:,:,c][edgeIndex+30:])[0][0],
                    p0=[self.m_right, self.a_right])
</code></pre>

<p>rightFunc is defined as follows;</p>

<pre><code>def rightFunc(self, x, m, const):

    return np.exp(-(m*x + const))
</code></pre>

<p>As I understand it, the 'O' type refers to a python object, but I can't see what is causing this error.</p>

<p>Complete Error:</p>

<p><a href="http://i.stack.imgur.com/2HwF3.png" rel="nofollow"><img src="http://i.stack.imgur.com/2HwF3.png" alt="Image detailing the error received"></a></p>

<p>Any ideas for what I should investigate to get to the bottom of this?</p>

<p>From <a href="https://github.com/numpy/numpy/issues/4384" rel="nofollow">here</a>, apparently numpy struggles with index type.  The proposed solution is:</p>

<blockquote>
  <p>One thing you can do is use np.intp as dtype whenever things have to do with indexing or are logically related to indexing/array sizes. This is the natural dtype for it and it will normally also be the fastest one.</p>
</blockquote>

<p>Does this help?</p>

python python-2.7 scipy