My input array which I will call as scores
will have a shape of (500, 10):
import numpy as np
scores = np.random.randint(10, size=(500, 10))
scores.shape # (500, 10)
Now I will have an indexing array with a creative name called index
with shape (500, ):
index = np.random.randint(9, size=500)
index.shape # (500,)
The index array represents each index of a column in each row in scores
. The objective would be to return an array of (500,) scores that correspond to each index in index
per row.
An unvectorized equivalent of this procedure will look like below code:
score_vector = np.zeros(500)
for i, col in enumerate(index):
score_vector[i] = scores[i, col]
My goal: an uber fast numpy vectorized version of above using api I don't really know.