title: Fastest way to count array values above a threshold in numpy
body: <p>I have a numpy array containing 10^8 floats and want to count how many of them are >= a given threshold.  Speed is crucial because the operation has to be done on large numbers of such arrays. The contestants so far are </p>
  
  <pre><code>np.sum(myarray &gt;= thresh)
  
  np.size(np.where(np.reshape(myarray,-1) &gt;= thresh))
  </code></pre>
  
  <p>The answers at <a href="https://stackoverflow.com/questions/12995937/count-all-values-in-a-matrix-greater-than-a-value">Count all values in a matrix greater than a value</a> suggest that np.where() would be faster, but I've found inconsistent timing results.  What I mean by this is for <strong>some</strong> realizations and Boolean conditions np.size(np.where(cond)) is faster than np.sum(cond), but for some it is slower. </p>
  
  <p>Specifically, if a large fraction of entries fulfil the condition then np.sum(cond) is significantly faster but if a small fraction (maybe less than a tenth) do then np.size(np.where(cond)) wins. </p>
  
  <p>The question breaks down into 2 parts: </p>
  
  <ul>
  <li>Any other suggestions?</li>
  <li>Does it make sense that the time taken by np.size(np.where(cond)) increases with the number of entries for which cond is true? </li>
  </ul>