[a,b]) won't update with a or b

Hi there,

When c =[a, b]), I expect will change with, but it doesn’t.
The following codes show the idea.

import torch
from torch.autograd import Variable
a, b = Variable(torch.ones(1)), Variable(torch.ones(1))
c =[a, b]) = torch.ones(1)*2
print( = [1,1], not [2,1].
I wonder if this is a feature or will it be fixed?

Thanks for your help.

c =[a, b]) calculates the value of c every time you run it. This is a feature.

As a general rule, you shouldn’t modify because any change to is not stored in the computation graph and won’t be differentiated when backpropagating.

Thanks for your clarification :slight_smile: