I've got a manual way to reference the numpy array, but can't figure out how to do it in a numpy-like manner.
I am looking for a numpy-like equivalent of the following line:
np.array([arr[0,index[0]], arr[1,index[1]], arr[2,index[2]]]).reshape(3,1)
Here is the code (simplified to pinpoint the issue):
arr = np.arange(9).reshape(3,3)
index = np.array([2,0,1])
print(arr)
result = np.array([arr[0,index[0]], arr[1,index[1]], arr[2,index[2]]]).reshape(3,1)
print(result)
it produces the following:
[[0 1 2]
[3 4 5]
[6 7 8]]
[[2]
[3]
[7]]
I am looking for numpy-style code to achieve what the line
np.array([arr[0,index[0]], arr[1,index[1]], arr[2,index[2]]]).reshape(3,1)
is doing here, for example:
arr[:,index[:]]
Obviously, this doesn't work correctly, because index[:] denotes the whole row instead of picking just one corresponding value.
This must be very simple, I am just somehow stuck on it. Can't figure out how to do it without a long line that manually brings every index for every row. In my case I have thousands of rows and thousands of columns, so definitely can't use the manual way.