连接两个张量

Concat two tensors

我想连接两个大小为 a: torch.Size([16, 1])b: torch.Size([16, 120]) 的张量 尺寸 torch.Size([16, 121])

你能帮忙吗?

这里可以使用torch.cat()功能。

示例:

>>> 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])

你想要做的是连接第一维 (dim=1) 上的张量。