# How to append to a tensor in a loop

I have a for loop where each iteration will give a tensor in this shape: tensor([[[0., 1., 1., 2., 1., 1., 0.],
[0., 2., 1., 1., 2., 1., 0.],
[0., 1., 5., 3., 1., 1., 0.]]])

How can I append new tensors to this one and form a tensor in this shape at last:
(for example, in second iteration the tensor will be
tensor([[[0., 0., 1., 2., 1., 0., 0.],
[0., 0., 2., 3., 3., 0., 0.],
[0., 0., 1., 2., 2., 0., 0.]]]))
The expected output at last is:

tensor([[[0., 1., 1., 2., 1., 1., 0.],
[0., 0., 1., 2., 1., 0., 0.]],
[[0., 2., 1., 1., 2., 1., 0.],
[0., 0., 2., 3., 3., 0., 0.]],
[[0., 1., 5., 3., 1., 1., 0.],
[0., 0., 1., 2., 2., 0., 0.]]])

You can concatenate the tensors along the specific dimension.
Your question can be briefly expressed like below,

``````a = torch.Size(1, 3, 7)
b = torch.Size(1, 3, 7)

result = torch.cat((a, b), dim=1)
``````

Then, you can get the result tensor size of (1, 6, 7)
The sample code

``````for i in range(it):
try:
a = torch.cat((a, new_a), dim=1)
except:
a = new_a``````