How convert a list of torch.LongTensor to one torch.LongTensor?

I want to pull a batch of Variable to one Variable, or one Tensor?[ type = ‘list’ ----> type = ‘torch.LongTensor’] How can I deal with this problem.

4 Likes

Hi,

I think torch.stack will do what you want.

7 Likes

You may want to use torch.stack and torch.squeeze in conjunction. The first converts a list of tensors to a single stacked tensor, and the latter removes all dimensions=1, thus making your data compact.

3 Likes