I have a row A = [0 1 2 3 4]
and an index I = [0 0 1 0 1]
. I would like to extract the elements in A
indexed by I
, i.e. [2, 4]
.
My attempt:
import numpy as np
A = np.array([0, 1, 2, 3, 4])
index = np.array([0, 0, 1, 0, 1])
print(A[index])
The result is not as I expected:
[0 0 1 0 1]
Could you please elaborate on how to achieve my goal?