Merge images by mask
I'm trying to merge two images according to the values in a mask where at all points where the mask is 1, the resulting image has the values of the first image, and otherwise it has values of the second image. Does anyone know how it can be achieved in pytorch? Using numpy, it can be achieved using
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; img1 = np.random.rand(100,100,3)
&gt;&gt;&gt; img2 = np.random.rand(100,100,3)
&gt;&gt;&gt; mask = np.random.rand(100,100)&gt;.5
&gt;&gt;&gt; res = img2.copy()
&gt;&gt;&gt; res[mask] = img1[mask]


You are looking for np.where:
res = no.where(mask, img1, img2)

