Equivalent of Numpy's list.append() for differentiable Variables

Hi, I was wondering what is the equivalent of:

    var = []
    for i in range(0, num):
        newstuff = #dostuff

I’m trying to use torch.cat but it needs a starting Variable to concatenate against. Is there any other way?

var = [] 
for I in range(0, num):
    new_stuff = # do stuff 
var_tensor = torch.cat(var)

Should work if new_stuff is already a tensor


Hi, i think the last row shoule be var_tensor = torch.stack(var).

Example see here: How to turn a list of tensor to tensor? - #4 by dmadeka1