Combine multiple Variables to one

x is a Variable which has 3 dims.

x.size()[0] is sequence length
x.size()[1] is batch size.

I did something below(for LSTM’s input):

temp = []
for i in xrange(len(x)):
    temp.append(nn.Linear(512, 256)(x[i]))

As you can see here, I got many Variables stored in temp. But I what I want is to combine these new Variables into one Variable. How can I do it?

Many thanks.

1 Like

Perhaps you need torch.cat?

cat’s input should be tensors, but temp’s elements are Variables.

torch.cat also works with Variables.

1 Like