solve_ivp - TypeError: 'numpy.ndarray' object is not callable
solve_ivp - TypeError: 'numpy.ndarray' object is not callable
我正在为 class 编写下面的代码,但无论我尝试什么,我都无法弄清楚如何修复它,所以我可以继续前进。
def eqs(t, x):
return np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)],
[(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
f = lambda x, thresh: x >= thresh
z = lambda t: np.multiply((t >= 2), (t <= 4))
z_thresh = 0.5
y_thresh = 0.5
x_thresh = 0.5
x_0 = np.zeros([0,])
sol = int.solve_ivp(eqs, range(0, 6), x_0)
我整晚都在用头撞墙,不知道该怎么走。无论我尝试什么,它仍然会抛出“TypeError:'numpy.ndarray' object is not callable。”
编辑:回溯如下:
Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <module>
9 x0 = np.zeros([0,])
10
---> 11 sol = int.solve_ivp(eqns_a,range(0,6),x0)
12 plt.figure(1)
13 subplot(311)
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\ivp.py in solve_ivp(fun, t_span, y0, method, t_eval, dense_output, events, vectorized, args, **options)
540 method = METHODS[method]
541
--> 542 solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
543
544 if t_eval is None:
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\rk.py in __init__(self, fun, t0, y0, t_bound, max_step, rtol, atol, vectorized, first_step, **extraneous)
92 self.max_step = validate_max_step(max_step)
93 self.rtol, self.atol = validate_tol(rtol, atol, self.n)
---> 94 self.f = self.fun(self.t, self.y)
95 if first_step is None:
96 self.h_abs = select_initial_step(
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun(t, y)
136 def fun(t, y):
137 self.nfev += 1
--> 138 return self.fun_single(t, y)
139
140 self.fun = fun
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun_wrapped(t, y)
18
19 def fun_wrapped(t, y):
---> 20 return np.asarray(fun(t, y), dtype=dtype)
21
22 return fun_wrapped, y0
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <lambda>(t, x)
6 x_thresh = 0.5
7
----> 8 eqns_a = lambda t, x: np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
9 x0 = np.zeros([0,])
10
TypeError: 'numpy.ndarray' object is not callable
回溯告诉你问题出在
np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]]
所以我们寻找明显的函数调用,fn(...)
。 np.multiply
应该没问题,除非你重新定义它的位置。 f(...)
用 lambda
定义。 z(...)
还有。剩下 x(1)
和 x(0)
。什么是 x
?这是 lambda 函数参数。
我正在为 class 编写下面的代码,但无论我尝试什么,我都无法弄清楚如何修复它,所以我可以继续前进。
def eqs(t, x):
return np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)],
[(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
f = lambda x, thresh: x >= thresh
z = lambda t: np.multiply((t >= 2), (t <= 4))
z_thresh = 0.5
y_thresh = 0.5
x_thresh = 0.5
x_0 = np.zeros([0,])
sol = int.solve_ivp(eqs, range(0, 6), x_0)
我整晚都在用头撞墙,不知道该怎么走。无论我尝试什么,它仍然会抛出“TypeError:'numpy.ndarray' object is not callable。”
编辑:回溯如下:
Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <module>
9 x0 = np.zeros([0,])
10
---> 11 sol = int.solve_ivp(eqns_a,range(0,6),x0)
12 plt.figure(1)
13 subplot(311)
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\ivp.py in solve_ivp(fun, t_span, y0, method, t_eval, dense_output, events, vectorized, args, **options)
540 method = METHODS[method]
541
--> 542 solver = method(fun, t0, y0, tf, vectorized=vectorized, **options)
543
544 if t_eval is None:
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\rk.py in __init__(self, fun, t0, y0, t_bound, max_step, rtol, atol, vectorized, first_step, **extraneous)
92 self.max_step = validate_max_step(max_step)
93 self.rtol, self.atol = validate_tol(rtol, atol, self.n)
---> 94 self.f = self.fun(self.t, self.y)
95 if first_step is None:
96 self.h_abs = select_initial_step(
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun(t, y)
136 def fun(t, y):
137 self.nfev += 1
--> 138 return self.fun_single(t, y)
139
140 self.fun = fun
~\anaconda3\lib\site-packages\scipy\integrate\_ivp\base.py in fun_wrapped(t, y)
18
19 def fun_wrapped(t, y):
---> 20 return np.asarray(fun(t, y), dtype=dtype)
21
22 return fun_wrapped, y0
~\AppData\Local\Temp/ipykernel_7252/1552450284.py in <lambda>(t, x)
6 x_thresh = 0.5
7
----> 8 eqns_a = lambda t, x: np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]])
9 x0 = np.zeros([0,])
10
TypeError: 'numpy.ndarray' object is not callable
回溯告诉你问题出在
np.array([[(1 - np.multiply((1 - f(z(t), z_thresh)), (1 - f(x(1), y_thresh)))) - x(0)], [(1 - np.multiply((1 - f(z(t), z_thresh)),(1 - f(x(0), x_thresh)))) - x(1)]]
所以我们寻找明显的函数调用,fn(...)
。 np.multiply
应该没问题,除非你重新定义它的位置。 f(...)
用 lambda
定义。 z(...)
还有。剩下 x(1)
和 x(0)
。什么是 x
?这是 lambda 函数参数。