Change 1's to 0 and 0's to 1 in numpy array without looping
iverted = ~arr + 2  should do the work
Let's say I have a numpy array where I would like to swap all the 1's to 0 and all the 0's to 1 (the array will have other values, and there is nothing special about the 0's and 1's). Of course, I can loop through the array and change the values one by one.
Is there an efficient method you can recommend using? Does the np.where() method have an option for this operation?