I have a three dimensional array img of shape [1200,1600,3] and a two dimensional array labels of shape [1200,1600]. The first array is from an image, the second one is from labels in the image. Location [i,j] in the img array corresponds to an image pixel. I want to create a new array of the same dimension as the img array, such that for the pixels with label 0, the original array is unchanged, but all other pixels are whitened (255,255,255).
The code I am using is:
import numpy as np newimg=np.zeros((img.shape,img.shape,img.shape)) for i in range(0,img.shape): for j in range(0,img.shape): if labels[i][j]==0: newimg[i][j]=img[i][j] else: newimg[i][j]=np.array([255,255,255])
Is there a faster way of doing this?