Solved by ptrblck in post #2 
              
              
                torch.where should work: 
x = torch.randint(0, 256, (4, 1, 224, 224))
print(x.min(), x.max())
> tensor(0) tensor(255)
out = torch.where((30<=x) & (x<=40), x, 0)
print(out.unique())
> tensor([ 0, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40])