1

I want to get the values at indices of my_array.

indices = np.array([[[0],
        [1],
        [0]]])

my_array = np.array([[[1.1587323 , 1.75406635],
        [1.05464125, 1.29215026],
        [0.9784655 , 1.16957462]]])

I should get the following output:

output: array([[[1.1587323], [1.29215026], [0.9784655]]])

Is it possible without for loops or list comprehensions?

1 Answer 1

2

You can use np.take_along_axis:

np.take_along_axis(my_array, indices, axis=-1)
array([[[1.1587323 ],
        [1.29215026],
        [0.9784655 ]]])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.