Typeerror: Unsupported Operand Type(S) for ** or Pow(): 'List' and 'Int'

Python scipy: unsupported operand type(s) for ** or pow(): 'list' and 'list'

It looks like you're after element-wise power-raising?

Like a*x[i]**(b*x[i]) for each i?

In that case, you have to use the np.power function:

def func(x,a,b):
return a*np.power(x,b*x)

Then it works.

(As an aside, it may be worthwhile to convert x and y from lists to numpy arrays: np.array(x)).

how to fix unsupported operand type(s) for ** or pow: 'list' and 'int'

Looks like you have written decimalList instead of i in for loop:

def enk_blok(m):
decimalList = [int(i) for i in str(m)]
cipher = []
for i in decimalList:
cipherElement = mod(decimalList**e, n) # replace decimalList with i
cipher.append(cipherElement)
return ''.join(cipher)

Also, this line return ''.join(cipher) will raise an error, because cipherElement is an integer, and join method doesn't work with the list of integers, you should cast cipherElement to str.

I am getting this error unsupported operand type(s) for ** or pow(): 'str' and 'int'

input() returns a string, which has to be converted into a number.

So like

height= int(input("Enter Height in meter"))
weight= int(input (" Enter Weight in Kg "))
result = weight/(height**2)
print(result)

unsupported operand type(s) for ** or pow(): 'list' and 'int' error

Here is one way of doing it using a List Comprehension:

I = [1,2,3,4,5]
a = [(675 * 10**-9 * (i**3)) - (771 * 10**-7 * (i**2)) + (1792 * 10**-5 * i + 0.49239) for i in I]
print (a)

This prints the following answer:

[0.510233575, 0.5279269999999999, 0.545474325, 0.5628795999999999, 0.5801468750000001]


Related Topics



Leave a reply



Submit