In Pytorch, if I have a 2D tensor, how to iterate over this tensor to get every value changed
Consider the original tensor is $x$.

x = torch.tensor([[0.3333, 0.6667, 1.0000], [1.0000, 0.6667, 0.3333]])


produces

x

tensor([[ 0.3333,  0.6667,  1.0000],
        [ 1.0000,  0.6667,  0.3333]])


We can do a broadcasting and then cast it to an integer tensor

y = (3 * x - 1).int()
y

tensor([[ 0,  1,  2],
        [ 2,  1,  0]], dtype=torch.int32

)