gpt4 book ai didi

python - 无法将数组数据从 dtype ('O' ) 转换为 dtype ('float64' )

转载 作者:太空狗 更新时间:2023-10-29 22:25:16 55 4
gpt4 key购买 nike

我正在使用 scipy 的 curve_fit 来拟合一些数据的函数,并收到以下错误;

Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe'

它指向我代码中的这一行;

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定义如下;

def rightFunc(self, x, m, const):

return np.exp(-(m*x + const))

据我了解,'O' 类型指的是一个 python 对象,但我看不出是什么导致了这个错误。

完整的错误:

Image detailing the error received

关于我应该调查什么以弄清这个问题有什么想法吗?

最佳答案

为了防止对其他人有帮助,我使用了 numpy.array(wavelength,dtype='float64') 强制将列表中的对象转换为 numpy 的 float64。对我来说效果很好。

关于python - 无法将数组数据从 dtype ('O' ) 转换为 dtype ('float64' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39452792/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com