1

From a previous post, I learned how to change all values in a 2D-Array in a very fast and easy way:

e.g. set all values smaller than 255 to x:

arr[arr < 255] = x

Now I want to do something similar, but not just setting the value to x.

I want to manipulate the value in this array in a specific way when it's below a treshold.

arr[abs(arr) < threshold] = arr(*where condition is true*) - threshold*x

arr - theshold*x does not work, since arr is the complete array.

I think that a loop with np.where is needed to solve this problem which isn't quite easy as before. Is there any better way?

1 Answer 1

2

It should be pretty easy to extend what you've already done:

x = random.rand(100)
threshold = 0.2
indices = abs(x) < threshold
x[indices] = x[indices] - threshold*x[indices]
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.