I have a 3 dimensional uint8 numpy array. I want to increase all the elements by 1 which has these values: 0,1,3,16,17,18. And set others to 0. I have tried using traditional for loops which is really really slow.
Tried using python indexing techniques to set other values to 255 (which will later be changed to 0)
mask[(mask[:,:,:] != 0) & (mask[:,:,:] != 1) & (mask[:,:,:] != 3) & (mask[:,:,:] != 16) & (mask[:,:,:] != 17) & (mask[:,:,:] != 18)] = 255
Then increasing the values by 1
mask[(mask[:,:,:] == 0) & (mask[:,:,:] == 1) & (mask[:,:,:] == 3) & (mask[:,:,:] == 16) & (mask[:,:,:] == 17) & (mask[:,:,:] == 18)] = mask[:,:,:]+1 #gives me error
Then changing the 255 to 0
mask[mask[:,:,:] == 255] = 0
The middle operation gives me error
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How to do that efficiently. Preferably in one go. Not 3 times iterating the array.