torch维度拼接

Torch里有单独的拼接函数

torch.cat

torch.cat(inputs,dim=0)->Tensor

在给定维度上对输入的张量进行连接操作。

参数:

  • inputs (sequence of Tensors) – 可以是任意相同Tensor 类型的python 序列
  • dimension (intoptional) – 沿着此维连接张量序列。

例子:

>>> x=torch.rand(2,3)
>>> y=torch.rand(2,3)
>>> x
tensor([[0.0879, 0.5688, 0.4375],
        [0.5864, 0.4142, 0.3684]])
>>> y
tensor([[0.8037, 0.9369, 0.8289],
        [0.6108, 0.1406, 0.6218]])
>>> torch.cat((x,y),dim=1)
tensor([[0.0879, 0.5688, 0.4375, 0.8037, 0.9369, 0.8289],
        [0.5864, 0.4142, 0.3684, 0.6108, 0.1406, 0.6218]])

你可能感兴趣的:(python,pytorch,深度学习,python)