"unsupported operand type(s) for ** or pow() : ' function' and 'int' "

"unsupported operand type(s) for ** or pow() : ' function' and 'int' "

我正在尝试求解 耦合 ODE。它包含一个提升到 2 次幂的函数。

出现以下错误:

"unsupported operand type(s) for ** or pow() : ' function' and 'int'  "  

函数是:

def psy_trial1(x,params,psy0=0):
    return x*(neural_neural(params,x)
def psy_trial2(x,params, psy0=0):
    return 1+x*neural_network(params,x)
def psy1(x, psy_trial1):
    return A(x)+B(x)*(psy_trial1)**2-psy_trial2

我认为问题出在功能上。编写具有某种整数幂的函数的正确方法是什么?

如有任何建议或帮助,我们将不胜感激。

问题是您试图获得函数 psy_trial1 的能力,而不是该函数的值 return,以解决您必须调用该函数的问题。 我发现的另一个错误是,在 psy1 函数中 return 语句的末尾,您试图减去函数 psy_trial2。所有修复都在这里:

def psy_trial1(x,params,psy0=0):
    return x*(neural_neural(params,x)
def psy_trial2(x,params, psy0=0):
    return 1+x*neural_network(params,x)
def psy1(x, psy_trial1):
    return A(x)+B(x)*(psy_trial1())**2-psy_trial2()