ptrblck:

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])


Super, that’s precisely what I wanted to do!
And also is much less tricky than I implemented it before…
Thanks a lot!!!