pytorch concatenate list of tensors code example
Example 1: torch concat matrix
third_tensor = torch.cat((first_tensor, second_tensor), 0) # keep column width append in rows
third_tensor = torch.cat((first_tensor, second_tensor), 1) # keep row height and append in columns
Example 2: how can I covert a list of tensor into tensor?
l = list(torch.tensor([1,2,3]))
print(l)
>>>[tensor(1), tensor(2), tensor(3)]
k = torch.stack(l)
print(k)
>>>tensor([1, 2, 3])