Recommended way to replace several values in a tensor

Is there a batch way to replace several particular values? for example, old_new_value = [[2,22],[3,33]] , which means 2 should be replaced by 22, and 3 should be replaced by 33.
Can I have an efficient way to achieve this?
Example:
old_values = torch.Tensor([1, 2, 3, 4, 5])
old_new_value = [[2,22], [3,33]]
end_result = torch.Tensor([1, 22, 33, 4, 5])

1 Like