1

Let's say I have an array J and another array O of indices that I would like to restrict J to. If J was [1, 0, 9, 1] and O was [0, 3], something would happen to give me [1, 1]. Is there any numpy function for this?

1 Answer 1

1

You can slice numpy array by selected indexes:

import numpy as np

arr = np.array([1, 0, 9, 1])
arr = arr[[0, 3]]  # >> array([1, 1])
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.