Given an array like below:
np.arange(12).reshape(4,3)
Out[119]:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])
I want to select a single element from each of the rows using a list of indices [0, 2, 1, 2]
to create a 4x1
array of [0, 5, 7, 11]
.
Is there any easy way to do this indexing. The closest I could see was the gather
method in pytorch
.