快捷方式

torch.cat

torch.cat(tensors, dim=0, *, out=None) Tensor

在給定維度上拼接輸入序列 tensors 中的張量。所有張量除了拼接維度外必須具有相同的形狀,或者是一個大小為 (0,) 的一維空張量。

torch.cat() 可以被視為 torch.split()torch.chunk() 的逆操作。

torch.cat() 透過示例最容易理解。

另請參閱

torch.stack() 沿著一個新維度拼接輸入序列。

引數
  • tensors (Tensor 序列) – 提供的非空張量除了拼接維度外必須具有相同的形狀。

  • dim (int, 可選) – 拼接張量的維度

關鍵字引數

out (Tensor, 可選) – 輸出張量。

示例

>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.6580, -1.0969, -0.4614],
        [-0.1034, -0.5790,  0.1497]])
>>> torch.cat((x, x, x), 0)
tensor([[ 0.6580, -1.0969, -0.4614],
        [-0.1034, -0.5790,  0.1497],
        [ 0.6580, -1.0969, -0.4614],
        [-0.1034, -0.5790,  0.1497],
        [ 0.6580, -1.0969, -0.4614],
        [-0.1034, -0.5790,  0.1497]])
>>> torch.cat((x, x, x), 1)
tensor([[ 0.6580, -1.0969, -0.4614,  0.6580, -1.0969, -0.4614,  0.6580,
         -1.0969, -0.4614],
        [-0.1034, -0.5790,  0.1497, -0.1034, -0.5790,  0.1497, -0.1034,
         -0.5790,  0.1497]])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源