I have the following code:
import numpy as np
my_array = np.zeros((42, 123, 2021))
assert another_array.shape == (42, 123)
for i in range(42):
for j in range(123):
my_array[i, j, another_array[i, j]] = 1
where it is assumed that the values of another_array stay inside the correct range (i.e. the values of another_array are integers between 0 and 2020).
I would like to get rid of the two for-loops. Is there a way to vectorise something like this?