LamaMo
LamaMo

Reputation: 626

Concat two tensors

I want to concat two tensors of size a: torch.Size([16, 1]) and b: torch.Size([16, 120]) to be of size torch.Size([16, 121])

could you please help with that?

Upvotes: 0

Views: 1275

Answers (1)

Divyam Khanna
Divyam Khanna

Reputation: 98

Here you can use the torch.cat() function.

Example:

>>> a = torch.rand([16,1])
>>> b = torch.rand([16,120])
>>> a.size()
torch.Size([16, 1])
>>> b.size()
torch.Size([16, 120])
>>> c = torch.cat((a,b),dim=1)
>>> c.size()
torch.Size([16, 121])

What you want to do is to concatenate the tensors on the first dimension (dim=1).

Upvotes: 1

Related Questions