I would like to avoid for loops in this code snippet:
import numpy as np
N = 4
a = np.random.randint(0, 256, size=(N, N, 3))
m = np.random.randint(0, 2, size=(N, N))
for i, d0 in enumerate(a):
for j, d1 in enumerate(d0):
if m[i, j]:
d1[2] = 42
This is a simplified example where a is an N x N RGB image and m is a N x N mask, which sets masked elements of the 3rd channel: a[:, :, 2] only.