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?

asked Mar 19, 2021 at 10:45

2 Answers 2

1

You have to combine two conditions:

 arr[(arr>target_value) & (np.arange(len(arr)) > certain_value)]
answered Mar 19, 2021 at 10:48
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.

answered Mar 19, 2021 at 10:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.