title: Efficient way to restrict a numpy boolean selector to the first few true values
body: <p>I have a numpy boolean <code>selector</code> array which I can apply to array <code>a</code>. <em>(not actually random in the problem domain, this is just convenient for the example)</em>. But I actually want to select using only the first n True entries of <code>selector</code> <em>(up to n=3 in the example)</em>. So given <code>selector</code> plus a parameter <code>n</code>, how do I generate <code>select_first_few</code>, using numpy operations, thus avoiding an iterative loop?</p>
  
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; selector = np.random.random(10) &gt; 0.5
  &gt;&gt;&gt; a = np.arange(10)
  &gt;&gt;&gt; selector
  array([ True, False,  True,  True,  True, False,  True, False,  True,
         False])
  &gt;&gt;&gt; chosen, others = a[selector], a[~selector]
  &gt;&gt;&gt; chosen
  array([0, 2, 3, 4, 6, 8])
  &gt;&gt;&gt; others
  array([1, 5, 7, 9])
  &gt;&gt;&gt; select_first_few = np.array([ True, False,  True,  True,  False, False,  False, False,  False,
  ...        False])
  &gt;&gt;&gt; chosen_few, tough_luck = a[select_first_few], a[~select_first_few]
  &gt;&gt;&gt; chosen_few
  array([0, 2, 3])
  &gt;&gt;&gt; tough_luck
  array([1, 4, 5, 6, 7, 8, 9])
  </code></pre>