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
How to Add Pandas Data to an Existing CSV File
How to Read from S3 in Pyspark Running in Local Mode
Tf.Data.Dataset: How to Get the Dataset Size (Number of Elements in an Epoch)
How to Make Multiple Empty Lists in Python
Import a File from a Subdirectory
How to Do an Upsert With Sqlalchemy
How to Change Milliseconds to Seconds in Python
How to Convert Np.Int64 into Python Int64 for Pandasseries
Display Multiple Images in One Ipython Notebook Cell
Most Efficient Way to Construct Similarity Matrix
Pandas Extract Numbers from Column into New Columns
Adding Months to a Pandas Object in Python
Python - How to Fix "Valueerror: Not Enough Values to Unpack (Expected 2, Got 1)"
Pandas Open_Excel() Fails With Xlrd.Biffh.Xlrderror: Can't Find Workbook in Ole2 Compound Document