I'm confronted with concatenating three tensors together so that 3 px1 tensors become one 3px1 tensor.
The most succinct I could come up with was:
torch.Tensor{v2:totable(),v4:totable(),v6:totable()}:view(3*p,1)
Are there ways to do this without converting to tables and back to tensors? It seems like there should be a generic way of concatenating tensors along some specified dimension assuming they have compatible shapes.
I can see how it would be possible to write such a function, does one not exist?
Two tensors of the same size can be added together by using the + operator or the add function to get an output tensor of the same shape.
How to append to a torch tensor? This is achieved by using the expand function which will return a new view of the tensor with its dimensions expanded to larger size. It is important to do because at some time if we have two tensors one is of smaller dimension and another is of larger one.
a = torch.randn(3,1)
b = torch.randn(3,1)
c = torch.randn(3,1)
d = torch.cat(a,b,1):cat(c,1)
print(d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With