I'm trying to index N values in a NxM numpy array, 1 in each row. The Indices are ordered in a list.
The way to normally index a multidimensional array is
import numpy as np
a = np.arange(12).reshape(3,4)
a[2,3] # 11
for multiple indices:
a[[1,1],[0,2]] # array([4,6])
So, for my question, I'm trying to achieve this:
i = [1,2,1]
a[np.arange(3), i] # array([1,6,9])
I'm wondering if the row indices can be given in an implicit way. I thought that the semicolon operator would help out, but it gives me the complete columns.