Stacking a list of tensors whose dimensions are unequal

Hello, I have a simple problem where I am trying to stack a list of 2D tensors that have unequal number of rows. For example data is a list of 2D tensors and

data[0].size() = (15,2)
data[1].size() = (14,2)
data[2].size() = (7,2)

I tried using torch.stack(data, dim=0) and torch.stack(data, dim=1) but they both gave me an error. Basically what I am trying to achieve is to stack them in the first dimension, giving me

stacked_data.size() = (36,2)
1 Like

Ok the solution was to simply use torch.cat(data,dim=0). Doh.

2 Likes