![](/img/trans.png)
[英]typeerror unsupported operand type(s) for %: 'list' and 'int'
[英]TypeError: 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_1
, cc
, dd
, gg
1.如何检查变量类型 :
使用'type`内置函数获取变量的类型。
演示 :
>>> d
[1, 2, 3]
>>> type(d)
<type 'list'>
>>>
2.关于例外 :
当我们运行此异常来/
在操作list
和int
的变量。
演示 :
>>> 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_1
和params
值,因此我们可以为您提供代码错误的地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.