I am trying to get a history of values of x with ‘for’ statement.
For python floats, I get the expected list.
The result is surprising with tensors: all entries of the list are the same!
Please let me know why this happens with tensors. Thanks.
— code —
import torch

# when x is a python float

x_hist = []
x = 1.1

for i in range(3):
    x -= 0.1
    x_hist.append(x)

print(x_hist)  
# out [1.0, 0.9, 0.8]

# when x is a tensor

x_hist = []
x = torch.tensor(1.1)

for i in range(3):
    x -= 0.1
    x_hist.append(x)

print(x_hist)  
# out [tensor(0.8000), tensor(0.8000), tensor(0.8000)]