title: How to transform negative elements to zero without a loop?
body: <p>If I have an array like</p>
  
  <pre><code>a = np.array([2, 3, -1, -4, 3])
  </code></pre>
  
  <p>I want to set all the negative elements to zero: <code>[2, 3, 0, 0, 3]</code>. How to do it with numpy without an explicit for? I need to use the modified <code>a</code> in a computation, for example</p>
  
  <pre><code>c = a * b
  </code></pre>
  
  <p>where <code>b</code> is another array with the same length of the original <code>a</code></p>
  
  <h1>Conclusion</h1>
  
  <pre><code>import numpy as np
  from time import time
  
  a = np.random.uniform(-1, 1, 20000000)
  t = time(); b = np.where(a&gt;0, a, 0); print ("1. ", time() - t)
  a = np.random.uniform(-1, 1, 20000000)
  t = time(); b = a.clip(min=0); print ("2. ", time() - t)
  a = np.random.uniform(-1, 1, 20000000)
  t = time(); a[a &lt; 0] = 0; print ("3. ", time() - t)
  a = np.random.uniform(-1, 1, 20000000)
  t = time(); a[np.where(a&lt;0)] = 0; print ("4. ", time() - t)
  a = np.random.uniform(-1, 1, 20000000)
  t = time(); b = [max(x, 0) for x in a]; print ("5. ", time() - t)
  </code></pre>
  
  <ol>
  <li>1.38629984856</li>
  <li>0.516846179962      &lt;- faster a.clip(min=0);</li>
  <li>0.615426063538</li>
  <li>0.944557905197</li>
  <li>51.7364809513</li>
  </ol>