无法将数组数据从 dtype('O') 转换为 dtype('float64') [英] Cannot cast array data from dtype('O') to dtype('float64')

查看:90
本文介绍了无法将数组数据从 dtype('O') 转换为 dtype('float64')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

rightFunc is defined as follows;

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

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

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

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

完全错误:

对于我应该调查的内容有什么想法吗?

Any ideas for what I should investigate to get to the bottom of this?

推荐答案

通常这些 scipy 函数需要如下参数:

Typically these scipy functions require parameters like:

curvefit( function, initial_values, (aux_values,), ...)

aux_values 的元组与主变量的当前值一起传递给您的 function.

where the tuple of aux_values is passed through to your function along with the current value of the main variable.

dstack 表达式是这个 aux_values 吗?或者几个的串联.它可能需要包含在 tuple 中.

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

(np.dstack(transmitted[:,:,c][edgeIndex+30:])[0][0],)

我们可能需要确切地知道此错误发生的位置,而不仅仅是代码的哪一行.我们需要知道正在转换什么值.哪里有带有 dtype 对象的数组?

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?

这篇关于无法将数组数据从 dtype('O') 转换为 dtype('float64')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆