Python 类型错误:不支持 / 的操作数类型:'list' 和 'int'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35502466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: unsupported operand type(s) for /: 'list' and 'int'
提问by sirius123
I got the below error:
我收到以下错误:
unsupported operand type(s) for /: 'list' and 'int'
不支持 / 的操作数类型:'list' 和 'int'
How do I solve this problem? Any idea?
我该如何解决这个问题?任何的想法?
Here is my code:
这是我的代码:
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)
回答by Vivek Sable
Check data type of all variable i.e. xdata_1
,cc
,dd
,gg
检查所有变量的数据类型,即xdata_1
, cc
, dd
,gg
1. How to check type of variable:
1. 如何检查变量类型:
Use 'type` inbuilt function to get type of variable.
使用 'type' 内置函数来获取变量的类型。
Demo:
演示:
>>> d
[1, 2, 3]
>>> type(d)
<type 'list'>
>>>
2. About Exception:
2. 关于异常:
This exception come when we operate /
operation on list
and int
variables.
当我们/
对list
和int
变量进行操作时会出现这种异常。
Demo:
演示:
>>> 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. Give input:
3. 提供输入:
Best to provide input details in the question i.e. value of xdata_1
and params
, so we can give you where code is wrong.
最好在问题中提供输入详细信息,即xdata_1
和 的值params
,以便我们可以告诉您代码错误的地方。