torch.tile#
- torch.tile(input, dims) Tensor#
透過重複
input的元素來構造張量。dims引數指定每個維度的重複次數。如果
dims指定的維度少於input的維度,則會在dims前面加上 ones,直到指定所有維度。例如,如果input的形狀為 (8, 6, 4, 2) 且dims為 (2, 2),則dims被視為 (1, 1, 2, 2)。類似地,如果
input的維度少於dims指定的維度,則input會被視為在維度零處進行了 unsqueeze,直到其維度與dims指定的維度數量相同。例如,如果input的形狀為 (4, 2) 且dims為 (3, 3, 2, 2),則input會被視為具有形狀 (1, 1, 4, 2)。注意
此函式類似於 NumPy 的 tile 函式。
示例
>>> 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]])