Torch.where is what you should then use.
That said, those legitimate small values can be mean to you.
In general, it is a good idea to know what you’d do in Python (PyTorch or numpy), which most often translates to Libtorch I  a  straightforward way.
Best regards
Thomas