0

I am trying to change all the values of a 3D numpy array situated between 2 other values such as:

array = np.random.randint(0,256,(44,640,640))
array[array < 93 and array != 0] = 1
array[array >= 93] = 7

However, this syntax does not work. What is the correct way to perform this operation ?

Thank you

1 Answer 1

2

Almost there. You need to fix your condition like this:

array = np.random.randint(0,256,(44,640,640))
array[(array < 93) & (array != 0)] = 1
array[array >= 93] = 7
Sign up to request clarification or add additional context in comments.

2 Comments

That was so simple ! I am sorry to have ask such a pity question. I hope it helps someone else in the future tho. Thank you very mich Ehsan !
@Unic0 Glad it helped :)

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.