Solved by sdv4 in post #2 
              
              
                If im is your torch.tensor of shape (L, W, 3), then it would be the same as in numpy: 
im[:, :, 0][im[:, :, 0] == 0.4] = 0.54
im[:, :, 1][im[:, :, 1] == 0.4] = 0.27
im[:, :, 2][im[:, :, 2] == 0.4] = 0.07

There is probably a nicer way to do it in one line, but this will work and is more clear than …