Solved by ptrblck in post #2 
              
              
                Try to unsqueeze Y in dim1: 
B, C, H, W = 2, 3, 4, 4
x = torch.randn(B, C, H, W)
y = torch.randn(B, H, W)

mask = (y.unsqueeze(1)>0).float()
output = x * mask - (1 - mask)

Would that work for you?