As far as I understand you problem, you have two matrices. Let’s name them m = [N, N] and x = [batch_size, N, N, F].
Somewhere in m are zeros and you would like to get the indices.
Using these indices you would like to set all matrices in x for each batch and each F to zero.
Is this the right understanding?
If so, you could try the following:
batch_size = 5
F = 7
N = 5

# Create m matrix and mask some values
m = torch.randn(N, N)
m[0, 4] = 0
m[2, 1] = 0
m[4, 3] = 0
print(m)

# Get zero indices
mask_idx = (m == 0).nonzero()

# Create x and mask same indices
x = torch.randn(batch_size, N, N, F)
x[:, mask_idx[:, 0], mask_idx[:, 1], :] = 0

# Print some results
print(x[0, :, :, 0])
print(x[1, :, :, 0])
print(x[2, :, :, 3])