Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 354
sirius123 Avatar asked Feb 19 '16 10:02

sirius123


People also ask

How do I fix unsupported operand type s?

The Python "TypeError: unsupported operand type(s) for /: 'str' and 'int'" occurs when we try to use the division / operator with a string and a number. To solve the error, convert the string to an int or a float , e.g. int(my_str) / my_num .

How do you fix unsupported operand type S for NoneType and int?

Unsupported operand type(s) for +: 'NoneType' and 'int' # The Python "TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'" occurs when we try to use the addition (+) operator with a None value. To solve the error, figure out where the variable got assigned a None value and correct the assignment.

What does unsupported operand type S for /: STR and STR mean?

The Python "TypeError: unsupported operand type(s) for -: 'str' and 'str'" occurs when we try to use the subtraction - operator with two strings. To solve the error, convert the strings to int or float values, e.g. int(my_str_1) - int(my_str_2) .


1 Answers

Check data type of all variable i.e. 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 i.e. value of xdata_1 and params, so we can give you where code is wrong.

like image 123
Vivek Sable Avatar answered Oct 23 '22 05:10

Vivek Sable