gpt4 book ai didi

python - 类型错误:不支持的操作数类型/: 'list' 和 'int'

转载 作者:太空宇宙 更新时间:2023-11-04 03:18:20 24 4
gpt4 key购买 nike

我收到以下错误:

unsupported operand type(s) for /: 'list' and 'int'

我该如何解决这个问题?任何想法?

这是我的代码:

def func(xdata_1,cc,dd,gg):
return cc*(xdata_1**(dd))*
(10**(-1.572*gg*( (185/((xdata_1/420)**2 + (420/xdata_1)**2 + 90 )) )

params,pcov = curve_fit(func,xdata_1,ydata_1,
sigma=err_1, absolute_sigma=True)

fc_1 = func(xdata_1, *params)

最佳答案

检查所有变量的数据类型,即 xdata_1ccddgg

<强>1。如何检查变量类型:

使用'type'内置函数获取变量的类型。

演示:

>>> d
[1, 2, 3]
>>> type(d)
<type 'list'>
>>>

<强>2。关于异常:

当我们对 listint 变量进行 / 操作时会出现这个异常。

演示:

>>> d = [1,2,3]
>>> d/4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: 'list' and 'int'
>>>

<强>3。提供意见:

最好在问题中提供输入详细信息,即 xdata_1params 的值,这样我们可以告诉您代码错误的地方。

关于python - 类型错误:不支持的操作数类型/: 'list' 和 'int',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502466/

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