I am using scipy's curve_fit to fit a function to some data, and receive the following error;
Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'
which points me to this line in my 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])
rightFunc is defined as follows;
def rightFunc(self, x, m, const):
return np.exp(-(m*x + const))
As I understand it, the 'O' type refers to a python object, but I can't see what is causing this error.
Complete Error:
Any ideas for what I should investigate to get to the bottom of this?
wavelength
? You have it wrapped in a call tonp.array()
, so I assume it is not a numpy array already. Presumably it is some sort of container (python list? PandasDataFrame
orSeries
? Something else?). What does the data inwavelength
look like? Also ask the same questions abouttransmitted
.float
using.astype(float)
? this solved my problem. more info here.