title: How to write a function to process arrays as input element by element and returns array
body: <p>I am trying to write a function and I want it to return one element when the input is element and an array of outputs if the input is array such that each element of output array is associated with the same place in input array. I am giving a dummy example:</p>
  
  <pre><code>import numpy as np
  def f(a):
      if a&lt;5:
          print a;
  f(np.arange(11))
  </code></pre>
  
  <p>This code returns the error:
      if a&lt;5:</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 expect the output to be:</p>
  
  <pre><code>0
  1
  2
  3
  4
  </code></pre>
  
  <p>How can I make it to work the way I explained as I believe many python functions are working in this way?</p>
  
  <p>Thanks.</p>