[[+content_image]]
I
I
iramovich2021-07-11 11:49:15
Python
iramovich, 2021-07-11 11:49:15

How to glue tensors in PyTorch?

How do I glue three tensors in Pytorch

tensor()
tensor()
tensor([[16385, 2, 96, 21, 96, 21, 96]])

so that we get the following tensor:

tensor([[ 96, 20, 96, 21, 96, 960 , 577, 2, 96, 21,
96, 21, 96, 37954, 2, 96, 20, 96, 21, 96,
16385, 2, 96, 21, 96, 21, 96]])

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
Sergey Sokolov, 2021-07-11
@iramovich

import  torch 

a = torch.tensor([[ 96, 20, 96, 21, 96, 960, 577, 2, 96, 21, 96, 21, 96]])
b = torch.tensor([[37954, 2, 96, 20, 96, 21, 96]])
c = torch.tensor([[16385, 2, 96, 21, 96, 21, 96]])

torch.cat([a,b,c], 1)

###
tensor([[   96,    20,    96,    21,    96,   960,   577,     2,    96,    21,
            96,    21,    96, 37954,     2,    96,    20,    96,    21,    96,
         16385,     2,    96,    21,    96,    21,    96]])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question