I would like to access a multidimensional python array with an array of indexes, using the whole array to index the target element. Let me explain it better:
A = np.arange(4).reshape(2,2)
a = [1,1]
>>> A[a[0],a[1]]
3
My intention is to pass the array without hard-coding the indexes values and get the same result, that is the value A[1,1]
. I tried but the only way I found is working differently:
>>> A[a]
array([[2, 3],
[2, 3]])
What results is the construction of a new array where each value of the index array selects one row from the array being indexed and the resultant array has the resulting shape (number of index elements, size of row).
Thank you.