Solved by michaelklachko in post #2 
              
              
                Maybe try something like this: 
T = torch.where(T > I + a, I + a, T) 
T = torch.where(T < I - a, I - a, T) 
https://pytorch.org/docs/stable/torch.html#torch.where