I have a list like [x1, x2, ..., xn]
, and xi
is a Tensor with size torch.Size([2, 3])
, how to convert this list a Tensor with size torch.Size([n, 2, 3])
. I am looking for an elegant method. Thanks for your reply.
You could use torch.stack
:
n = 10
l = [torch.randn(2, 3) for _ in range(n)]
t = torch.stack(l)
print(t.shape)
> torch.Size([10, 2, 3])