0

How do I modify a np array based on the current value and the index? When I just want to modify certain values, I use e.g. arr[arr>target_value]=0.5 but how do I only modify the values of arr > target_value where also the index is greater than a certain value?

2 Answers 2

1

You have to combine two conditions:

 arr[(arr>target_value) & (np.arange(len(arr)) > certain_value)]
Sign up to request clarification or add additional context in comments.

Comments

0

For that very specific example you would just use indexing I believe

eg arr[100:][arr[100:] > target_value]=0.5

in general it could be conceptually easier to do these two things separately. First figure out which indices you want, then check whether they satisfy whatever condition you want.

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.