Threshold for values

Hello,

Is it possible to apply a threshold to the output of a network without losing the ability to backprop ?
For instance, let’s say I have a Tensor of size 15, with values [0,1]. I want every value above 0.1 and below 0.9 to be equal to 0.5. Is there any PyTorch function to do so ?

Thanks !

 X.masked_fill((X > 0.1) * (X < 0.9), 0.5)

Definitely awesome, thanks !