I got the below error:
unsupported operand type(s) for /: 'list' and '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)
Check data type of all variable ie xdata_1
, cc
, dd
, gg
1. How to check type of variable :
Use 'type` inbuilt function to get type of variable.
Demo :
>>> d
[1, 2, 3]
>>> type(d)
<type 'list'>
>>>
2. About Exception :
This exception come when we operate /
operation on list
and int
variables.
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 :
Best to provide input details in the question ie value of xdata_1
and params
, so we can give you where code is wrong.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.