0

I'm working on the code below for a class and no matter what I try I can't figure out how to fix it so I can move on.

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)

I've been banging my head against the wall all night and can't figure out how to get around. No matter what I seem to try it still throws "TypeError: 'numpy.ndarray' object is not callable."

Edit: The traceback is as follows:

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
6
  • 1
    Please post the full error and a minimal reproducible example. That will also contain clues to help you find the cause of the problem. Commented Dec 1, 2021 at 21:15
  • You don't want to work your way around the problem, you need to first identify the problem. Which variable is an array, when it really should be function. Debugging is not a game of darts where through a whole lot of things at the problem in hopes of hitting the target! Commented Dec 1, 2021 at 21:33
  • Did you look at the error traceback? Try to identify where the problem occurs? You sure didn't think it important enough to show it to us!. Commented Dec 1, 2021 at 21:35
  • My apologies, I'm totally fried. I have added the traceback to the original post. Commented Dec 1, 2021 at 21:53
  • In the functions eqs, x is an array, not a function. Use x[0] and x[1] to index the array, not x(0) and x(1). Commented Dec 1, 2021 at 22:32

1 Answer 1

0

the traceback tells you that the problem is in

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)]]

So we look for apparent function calls, fn(...). np.multiply should be ok unless you redefined it somplace. f(...) is defined with a lambda. z(...) as well. That leaves x(1) and x(0). What is x? It's the lambda function argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.