def flatten(t):
    t = t.reshape(1, -1)
    t = t.squeeze()
    t[5] = 5
    return t

t = torch.ones(4, 3)
flatten(t)
print(t)

I couldn’t understand why the result is tensor([[1., 1., 1.],
[1., 1., 5.],
[1., 1., 1.],
[1., 1., 1.]]). I expected it to stay the original matrix of 1’s, because in the function, t is just a copy to the reference to the object. And after the first command: “t = t.reshape(1, -1)”, t is not referencing to a new object. (another object). the same happens to the next line. and when we try to change t (t[5] = 5), we changed a different object (because as said t is now referencing a new, another object).
so how come t changed?