Reputation: 891
I want to merge two tensors a
and b
into c
. What I've tried is:
But my expectation is c = [1, 2, 3, 4, 5, 6]
. How can I get it?
Upvotes: 2
Views: 16649
Reputation: 111
If you want to work with torch tensors, as this link suggests, you can do as following:
import torch
a = torch.Tensor([1,2,3])
b = torch.Tensor([4,5,6])
torch.cat((a,b))
output:
tensor([1., 2., 3., 4., 5., 6.])
and for stacking:
torch.stack((a,b))
output:
tensor([[1., 2., 3.], [4., 5., 6.]])
Upvotes: 0