title: Extract values from a 2D matrix based on the values of one column
body: <p>I have a 2D numpy array "X" with m rows and n columns. I am trying a extract a sub-array when the values of the column r fall in a certain range. Right now I have implemented this by looping through each and every row, which as expected is really slow. What is the simpler way to do this in python?</p>
  
  <pre><code>    for j in range(m):
          if ((X[j,r]&gt;=lower1) &amp; (X[j,r]&lt;=upper1)):
              count=count+1
              if count==1:
                  X_subset=X[j,:]
              else:
                  X_subset=np.vstack([X_subset,X[j,:]])
  </code></pre>
  
  <p>For example:</p>
  
  <pre><code>X=np.array([[10,3,20],
              [1,1,25],
              [15,4,30]])
  </code></pre>
  
  <p>I want to get the subset of this 2D array if the values of second column are in the range 3 to 4 (r=1, lower1=3, upper1=4). The result should be:</p>
  
  <pre><code>[[ 10  3  20]
   [ 15  4  30]]
  </code></pre>