2
I have an array in three dimensions (x, y and z) and an address vector. This vector has a size equal to the x dimension of the array, and its objective is for each x to point a y bringing their respective z, that is, the expected result is dimension (x, z).
Below is an example of code, which works as expected, but someone knows if you have any Numpy function with which I can replace the loop for and solve the problem more optimally?
arr = np.random.rand(100,5,2)
result = np.random.rand(100,2)
id = [np.random.randint(0, 5) for _ in range(100)]
for i in range(100):
result[i] = arr[i,id[i]]
Thank you, you helped me a lot.
– Allan