Issue with torch.stack()

Hello everyone.

I’m having problems with torch.stack(), I reported a small example with the error that I get

import torch
a = torch.zeros(3,2,1,2)
b = torch.zeros(2,2,1,2)
torch.stack([a,b], dim=0)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 2 in dimension 1 at /opt/conda/conda-bld/pytorch_1550780889552/work/aten/src/TH/generic/THTensorMoreMath.cpp:1307

why do I have this error message?

As you can see from the official documentation torch.stack requires tensors of the same size.
The output will be a tensor with a new extra dimension in position 0 with value equal to the number of tensors stacked.

In your case dimension 0 of your original tensors (which is dimension 1 of the resulting tensor) does not match.

Maybe you wanted to concatenate the tensors, in this case you can try with:[a,b]) # output size is (5,2,1,2)