sirius123
sirius123

Reputation: 123

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)

Upvotes: 8

Views: 81312

Answers (2)

Krunal Brahmankar
Krunal Brahmankar

Reputation: 1

Calculate the mean of two arrays num1 and num2

p=[x / l for x in sum1]
print(p)
for ele in range(0,len(p)):
  total=total + p[ele]
print(total)

The answer is 3.5, which is indeed the mean of the two arrays or list num1 and num2.

The full code:

num1=[1,2,3]
num2=[4,5,6]
total=0
sum1=num1+num2
print(sum1)
l=len(sum1)
print(l)
p=[x / l for x in sum1]
print(p)
for ele in range(0,len(p)):
  total=total + p[ele]
print("MEDIAN is",total)

Which outputs

[1, 2, 3, 4, 5, 6]
6
[0.16666666666666666, 0.3333333333333333, 0.5, 0.6666666666666666, 0.8333333333333334, 1.0]
MEAN IS 3.5

Upvotes: -4

Vivek Sable
Vivek Sable

Reputation: 10223

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.

Upvotes: 7

Related Questions