title: Convert real-valued numpy array to binary array by sign
body: <p>I am looking for a fast way to compute the following:</p>
  
  <pre><code>import numpy as np
  a = np.array([-1,1,2,-4,5.5,-0.1,0])
  </code></pre>
  
  <p>Now I want to cast <code>a</code> to an array of binary values such that it has a 1 for every positive entry of <code>a</code> and a 0 otherwise. So the result I want is this:</p>
  
  <pre><code>array([ 0.,  1.,  1.,  0.,  1.,  0.,  0.])
  </code></pre>
  
  <p>One way to achieve this would be</p>
  
  <pre><code>np.array([x if x &gt;=0 else 0 for x in np.sign(a)])
  array([ 0.,  1.,  1.,  0.,  1.,  0.,  0.])
  </code></pre>
  
  <p>But I am hoping someone can point out a faster solution. </p>
  
  <pre><code>%timeit np.array([x if x &gt;=0 else 0 for x in np.sign(a)])
  100000 loops, best of 3: 11.4 us per loop
  </code></pre>
  
  <p><strong>EDIT:</strong> timing the great solutions from the answers</p>
  
  <pre><code>%timeit (a &gt; 0).astype(int)
  100000 loops, best of 3: 3.47 us per loop
  </code></pre>