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>Typically these <code>scipy</code> functions require parameters like:</p>

<pre><code>curvefit( function, initial_values, (aux_values,), ...)
</code></pre>

<p>where the tuple of <code>aux_values</code> is passed through to your <code>function</code> along with the current value of the main variable.</p>

<p>Is the <code>dstack</code> expression this <code>aux_values</code>?  Or a concatenation of several.  It may need to be wrapped in a <code>tuple</code>.</p>

<pre><code>(np.dstack(transmitted[:,:,c][edgeIndex+30:])[0][0],)
</code></pre>

<p>We may need to know exactly where this error arises, not just which line of your code does it.  We need to know what value is being converted. Where is there an array with dtype object?</p>

python python-2.7 scipy