我的代码有问题。我想为一个模型的引用解决方案,该模型应描述熊和鳟 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/