捷徑

torch.tile

torch.tile(input, dims) Tensor

透過重複 input 的元素來建構張量。dims 參數指定每個維度中的重複次數。

如果 dims 指定的維度數量少於 input 擁有的維度數量,則會在 dims 前面補上 1,直到所有維度都被指定。例如,如果 input 的形狀為 (8, 6, 4, 2),而 dims 為 (2, 2),則 dims 會被視為 (1, 1, 2, 2)。

類似地,如果 input 擁有的維度數量少於 dims 指定的維度數量,則 input 會被視為在維度 0 上執行了 unsqueeze 操作,直到它擁有與 dims 指定的維度數量相同的維度數量。例如,如果 input 的形狀為 (4, 2),而 dims 為 (3, 3, 2, 2),則 input 會被視為具有形狀 (1, 1, 4, 2)。

注意

此函數類似於 NumPy 的 tile 函數。

參數
  • input (Tensor) – 要重複其元素的張量。

  • dims (tuple) – 每個維度的重複次數。

範例

>>> x = torch.tensor([1, 2, 3])
>>> x.tile((2,))
tensor([1, 2, 3, 1, 2, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.tile(y, (2, 2))
tensor([[1, 2, 1, 2],
        [3, 4, 3, 4],
        [1, 2, 1, 2],
        [3, 4, 3, 4]])

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發者的深度教學

檢視教學

資源

尋找開發資源並獲得您的問題解答

檢視資源