title: How can I isolate rows in a 2d numpy matrix that match a specific criteria?
body: <p>How can I isolate rows in a 2d numpy matrix that match a specific criteria?  For example if I have some data and I only want to look at the rows where the 0 index has a value of 5 or less how would I retrieve those values?</p>
  
  <p>I tried this approach:</p>
  
  <pre><code>import numpy as np
  
  data = np.matrix([
      [10, 8, 2],
      [1, 4, 5],
      [6, 5, 7],
      [2, 2, 10]])
  
  #My attempt to retrieve all rows where index 0 is less than 5
  small_data = (data[:, 0] &lt; 5)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>matrix([
      [False],
      [ True],
      [False],
      [ True]], dtype=bool)
  </code></pre>
  
  <p>However I'd like the output to be:</p>
  
  <pre><code>   [[1, 4, 5],
      [2, 2, 10]]
  </code></pre>
  
  <p>Another approach may be for me to loop through the matrix rows and if the 0 index is smaller than 5 append the row to a list but I am hoping there is a better way than that. </p>
  
  <p>Note: I'm using Python 2.7.</p>