Suppose that you have a 1D numpy array containing elements that are either 3 or 4
for example:
3
4
4
4
3
3
3
I would like to alter this array so that if an element is 3 then it should become some number X and if the element is 4 it should become some number Y. It is guaranteed that X is different than Y. For the above array we would get:
X
Y
Y
Y
X
X
X
I was thinking about doing something like this:
arr[arr==3]=X
arr[arr==4]=Y
however, what if X is 4? Then in the end the entire array will contain just Ys.
I am trying to avoid using a for loop for performance reasons, but if it's the only way to go, I can afford following that route.