![](/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.