I'm currently working on creating a mask for an image. I have initialized a two-dimensional numpy zeros array. I now want to replace the values of the mask corresponding to pixels following some conditions such as x1< x < x2 and y1 < y < y2 (where x and y are the coordinates of the pixels) to 1.
Is there an easier way to do it (maybe through slicing) without looping through the mask like below
clusterMask = np.zeros((h, w))
for x in range(h):
for y in range(w):
if x <= clusterH + 2 * S and x >= clusterH - 2*S and y <= clusterW + 2*S and y >= clusterW - 2*S:
clusterMask[x][y] = 1
clusterMask[clusterH - 2*S:clusterH + 2*S, clusterW - 2*S : clusterW + 2*S] = 1
\$\endgroup\$