Pulling elements from 2D array based on index array
<p>I have an array as:</p>

<pre><code>import numpy as np
A = np.arange(15).reshape(3, 5)
</code></pre>

<p>I also have an index array as:</p>

<pre><code>ind = np.asarray([1,2,0,2,2])
</code></pre>

<p>The elements of ind represent the row number of A for each column of A.</p>

<p>i.e </p>

<p>I want to pull <code>ind[0] = 1</code> element from column 0 of A
I want to pull <code>ind[4] = 2</code> element from column 4 of A</p>

<p>Desired output is:</p>

<pre><code>5, 11, 2, 13, 14
</code></pre>

<p>Using <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing" rel="nofollow">Numpy's <code>fancy-indexing</code></a> -</p>

<pre><code>A[ind,np.arange(ind.size)]
</code></pre>

python numpy