title: Faster way to split a numpy array according to a threshold
body: <p>Suppose I have a random numpy array:</p>
  
  <pre><code>X = np.arange(1000)
  </code></pre>
  
  <p>and a threshold:</p>
  
  <pre><code>thresh = 50
  </code></pre>
  
  <p>I want to split <code>X</code> in two partitions <code>X_l</code> and <code>X_r</code> in such a way that every element in <code>X_l</code> is less or equal to <code>thresh</code> while in <code>X_r</code> each element is greater than <code>thresh</code>. After that these two partitions are given to a recursive function.</p>
  
  <p>Using numpy I create a boolean array and I use it to partition <code>X</code>:</p>
  
  <pre><code>Z = X &lt;= thresh
  X_l, X_r = X[Z == 0], X[Z == 1]
  recursive_call(X_l, X_r)
  </code></pre>
  
  <p>This is done several times, is there a way to make things faster? Is it possible to avoid creating a copy of the partitions at each call?</p>