filtering numpy matrix on a column
<p>I have a numpy matrix as follows:</p>

<pre><code>data = np.matrix(
      "5 3 1;"
      "4 4 1;"
      "6 4 1;"
      "8 2 1;"
      "3 5 1;"
      "1 7 1;"
      "5 4 1;"
      "0 1 0;"
      "2 0 0")
# Output:
matrix([[5, 3, 1],
    [4, 4, 1],
    [6, 4, 1],
    [8, 2, 1],
    [3, 5, 1],
    [1, 7, 1],
    [5, 4, 1],
    [0, 1, 0],
    [2, 0, 0]])
</code></pre>

<p>what I want is to filter the matrix on the third column whose value is 1; that is, I do not want to get the rows whose 3rd value is 0. In short, I want to extract the matrix below:</p>

<pre><code>matrix([[5, 3, 1],
    [4, 4, 1],
    [6, 4, 1],
    [8, 2, 1],
    [3, 5, 1],
    [1, 7, 1],
    [5, 4, 1]])
</code></pre>

<p>I tried a few combinations to filter it; but none of them worked for me. For instance, the following code rules out the rows with zero, but it returns only the first column.</p>

<pre><code>data[data[:,2]&gt;0]
#Output: 
matrix([[5, 4, 6, 8, 3, 1, 5]])
</code></pre>

<p>Is there a way to filter this matrix without explicitly writing loop statements?</p>