Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

python - TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

I don't know why i can x*2 and y*2 please help i need this i dont get why im getting this error... . . . . .. . . .. .. . . . . .

def regresion(lista,n):
a=0
b=0
if isinstance(n,int):
    a =((x**2)(y**2)-n(promx)(promy)) / (((x**2)**2)-n(promx**2))

    b =(promy-(n)(promx**2))
else:
    "n no es entero"
return a,b

def x(lista):
a=[]
c=0
x=0
if lista!=[]:
    for i in lista:
        c = i[0]
        a = a + [c]
    for i in a:
        x = x + i

    return x
def y(lista):
b=[]
d=0
y=0
if lista!=[]:
    for i in lista:
            d = i[1]
            b = b + [d]

    for i in b:
            y = y + i

    return y
def promx(lista):
a=[]
c=0
x=0
promx=0
if lista!=[]:
    for i in lista:
        c = i[0]
        a = a + [c]

    for i in a:
        x = x + i
    promx= x / len(a)

    return promx
def promy(lista):
b=[]
d=0
y=0
promy=0
if lista!=[]:
    for i in lista:
            d = i[1]
            b = b + [d]

    for i in b:
            y = y + i
    promy= y / len(b)
return promy
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your code is intented terribly and has too many dots, but I think this is the issue.

On this line:

a =((x**2)(y**2)-n(promx)(promy)) / (((x**2)**2)-n(promx**2))

You call:

promx**2

Which is raising promx to the power 2 using exponentiation.

However, promx is a function, so by calling promx**2 you are saying raise this function definition to the power 2. Which doesn't make sense. What you need to do is call promx with a value like so:

promx(X)**2

Where X is a list that fills the argument the function promx requires.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...