title: Numpy: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
body: <p>I know this error has been posted before but I am not sure how to proceed. I am wanting to write a function to return a square wave and then.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def V_in(t):
  
      v  = np.floor(2*t)      
  
      if v % 2 == 0   
          V_in = 1
      else: 
          V_in = -1
  
      return V_in
  
  
  t = np.arange(0,10,1000)
  
  square_wave = V_in(tpoints)
  
  plt.plot(tpoints, square_wave);
  </code></pre>
  
  <p>When I run it I get this error message:</p>
  
  <blockquote>
    <p>ValueError: The truth value of an array with more than one element is
    ambiguous. Use a.any() or a.all()</p>
  </blockquote>
  
  <p>I have found I can get it to work if I create a loop over all values of <code>t</code> and store them in an array but that doesn't work when I try to use it within a second function.</p>
  
  <pre><code>def f(V,t):
      return (V_in(t) - V)
  </code></pre>
  
  <p>Where <code>V</code> is an initial value. This second function is then used in the RK4 algorithm to solve for the voltage.</p>