Tensor.apply_ funtion - PyTorch Forums
discuss.pytorch.org › t › tensor-apply-funtionFeb 05, 2020 · torch.apply_ is slow, and we don’t have a great efficient way to apply an arbitrary function to a tensor, but a common workaround for simple operations can be to use a mask. E.g. say you wanted to do something like tensor.apply_( lambda x: x + 2 if x > 5 else x ) , instead you could write something like result = (tensor > 5) * 2 + tensor .