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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:31:37  来源:igfitidea点击:

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

pythonfunctionerror-handlingtypeerror

提问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 listand intvariables.

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

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_1and params, so we can give you where code is wrong.

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