title: Function of Numpy Array with if-statement
body: <p>I am using <a href="http://matplotlib.sourceforge.net/">Matplotlib</a> and <a href="http://numpy.scipy.org/">Numpy</a> to produce some plots. I wish to define a function which given an array returns another array with values calculated <em>elementwise</em>, for example:</p>
  
  <pre><code>def func(x):
       return x*10
  
  x = numpy.arrange(-1,1,0.01)
  y = func(x)
  </code></pre>
  
  <p>This is fine. Now however I wish to have an if-statement inside <code>func</code>, for example:</p>
  
  <pre><code>def func(x):
       if x&lt;0:
            return 0
       else:
            return x*10
  
  x = numpy.arrange(-1,1,0.01)
  y = func(x)
  </code></pre>
  
  <p>This unfortunately throws the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\Scripts\test.py", line 17, in &lt;module&gt;
      y = func(x)
    File "D:\Scripts\test.py", line 11, in func
      if x&lt;0:
  ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p>I looked at the documentation for <a href="http://www.scipy.org/Numpy_Example_List#head-147db17da53bc378c2f3f90d4f65f97f1bc6194c"><code>all()</code></a> and <a href="http://www.scipy.org/Numpy_Example_List#head-779ee45438f37a2b9e3f957eefc238835f7227c6"><code>any()</code></a> and they do not fit the bill for what I need. So is there a nice way to make the function handle arrays element wise as in the first example?</p>