Filtering through numpy arrays by one row's information
<p>I am asking for help on filtering through numpy arrays. I currently have a numpy array which contains the following information:</p>

<pre><code>[[x1_1, x1_2, ..., x1_n], [x2_1, x2_2, ..., x2_n], [y1, y2, ..., yn]
</code></pre>

<p>ie. the array is essentially a dataset where <em>x1, x2</em> are features (coordinates), and y is the output (value). Each data point has an appropriate <em>x1, x2</em>, and <em>y</em>, so for example, the info corresponding to data point <em>i</em> is <em>x1_i, x2_i</em>, and <em>yi</em>.</p>

<p>Now, I want to extract all the data points by filtering through y, meaning I want to know all the data points in which y > some value. In my case, I want the info (still with the same numpy structure) for all cases where y > 0. I don't really know how to do that -- I've been playing around with boolean indexing such as <code>d[0:2,y&gt;0]</code> or <code>d[d[2]&gt;0]</code>, but haven't gotten anywhere.</p>

<p>A clarifying example:</p>

<p>Given the dataset:</p>

<pre><code>d = [[0.1, 0.2, 0.3], [-0.1,-0.2,-0.3], [1,1,-1]]
</code></pre>

<p>I pull all points or instances where <code>y &gt; 0</code>, ie. <code>d[2] &gt; 0</code>, and it should return the values:</p>

<pre><code>[[0.1, 0.2],[-0.1,-0.2],[1,1]]
</code></pre>

<p>Any advice or help would be appreciated.</p>

<p>You can use:</p>

<pre><code>import numpy as np

d = np.array([[0.1, 0.2, 0.3], [-0.1,-0.2,-0.3], [1,1,-1]])
print (d)
[[ 0.1  0.2  0.3]
 [-0.1 -0.2 -0.3]
 [ 1.   1.  -1. ]]

#select last row by d[-1] 
print (d[-1]&gt;0)
[ True  True False]

print (d[:,d[-1]&gt;0])
[[ 0.1  0.2]
 [-0.1 -0.2]
 [ 1.   1. ]]
</code></pre>

python arrays numpy filter