Suppose I have a list tensors in the same size. Is there any unified function to merge all these like
np.array(array_list) in case you have list or numpy arrays.
This is my current solution
data = th.zeros([len(imgs), imgs.size(), imgs.size(), imgs.size()])
for i, img in enumerate(imgs):
data[i] = img
just in case you were wondering about the difference:
Concatenates sequence of tensors along a new dimension.
Concatenates the given sequence of seq tensors in the given dimension.
B are of shape (3, 4),
torch.cat([A, B], dim=0) will be of shape (6, 4) and
torch.stack([A, B], dim=0) will be of shape (2, 3, 4).
What if A is of shape (1,3,4) and B is (3,4)?
I want the result to be (2,3,4). How do I do this?
a = torch.rand(1, 3, 4)
b = torch.rand(3, 4)
b = b.unsqueeze(0)
c = torch.cat([a, b], dim=0)