python - “' numpy.ndarray ' object is not callable”

标签 python error-handling

我的代码有问题。我想为一个模型的引用解决方案,该模型应描述熊和鳟 fish 的种群及其相互联系。

我找不到我做错了什么,但是python调用了三行有问题的代码,并以错误“numpy.ndarray”对象不可调用为结尾。我究竟做错了什么?

import matplotlib.pyplot as plt 
import numpy as np
from scipy.interpolate import interp1d

def referenz_loesung(f, ref_loeser, x0, t0, T):
    print "Berechne Referenzloesung..."
    h_ref = 0.0001
    #it mentions the following line as problematic
    t_punkte, x_punkte = ref_loeser(f, x0, t0, T, h_ref) #it mentions this line as problematic

    print "Erstelle Funktionen aus Referenzloesungen mit Hilfe von Splines."
    a = interp1d(t_punkte, x_punkte[: , 0])
    b = interp1d(t_punkte, x_punkte[: , 1])
    return a, b


if __name__ == "__main__":
    def f(x, t): # Funktion aus vorherigen Uebungen der DGL: x'(t) = f(x(t), t)
        y = np.zeros(2)
        y[0] = -2*x[0] + 10 * x[1]
        y[1] = -x[0]
        return y

    x0 = np.array([1., 0.])
    t0 = 0
    T = 10
    h = 0.5

    from unsersolver import integriere
    #it mentions the following line as problematic
    t_punkte, x_werte = integriere (f, x0, t0, T, h) 

    from implEuler import integriere as ref_loeser 
    #it mentions the following line as problematic
    x1_ref, x2_ref = referenz_loesung(f,ref_loeser, x0, t0, T)
    ref_punkte = np.linspace(t0, T, 1000)

    from woche1_1_m import auswerten_nx1
    ref_werte1 = auswerten_nx1(x1_ref, ref_punkte)
    ref_werte2 = auswerten_nx1(x2_ref, ref_punkte)

我导入的内容来自前几周的其他文件,这些文件可以正常运行。
知道我能做什么吗?我刚开始学习python,所以我真的没有任何线索。
谢谢!

最佳答案

如果可以将代码发布给integriere()或ref_loeser(),则将更为有用。
有了这些信息,我就请您尝试追溯到问题的根源:

问题的开始是t_punkte, x_werte = integriere(f, x0, t0, T, h),您说它给出了一个numpy错误,由于要传递给它的唯一numpy参数是x0,因此建议您检查integriere()代码中x0的用法。

接下来,我建议不要将函数作为参数传递,我认为这不是标准约定。您可以在def ref_loeser(parameters..)函数调用之外定义refrenz_loesung(),然后像您一样调用它。

由于referenz_loesung()调用的ref_loeser()integriere()相同,因此我强烈建议您检查此函数中的代码。

祝好运!

关于python - “' numpy.ndarray ' object is not callable”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45013892/

相关文章:

PowerShell - 为整个脚本设置 $ErrorActionPreference

python - Python 控制台中的粗体格式

python - 通过 Simple-Salesforce 批量插入时间字段

php - @什么时候有用?

Python:对象中缺少 'self'(不会自动传递)

c# - 使ModelState持久,但不能太持久

python - Beautiful Soup - 任何指定的编码都会破坏美化格式

python - Caffe:如何通过代码获取 `solver.prototxt`参数?

python - 如何编写与普通 Python 值和 NumPy 数组兼容的条件代码?

python - 使用多处理时文件头被截断