快捷方式

torch.Tensor.repeat

Tensor.repeat(*repeats) Tensor

沿著指定的維度重複此張量。

expand() 不同,此函數會複製張量的資料。

警告

repeat() 的行為與 numpy.repeat 不同,但更類似於 numpy.tile。若要尋找與 numpy.repeat 相似的運算子,請參閱 torch.repeat_interleave()

參數

repeat (torch.Size, int..., tuple of int or list of int) – 沿著每個維度重複此張量的次數

範例

>>> x = torch.tensor([1, 2, 3])
>>> x.repeat(4, 2)
tensor([[ 1,  2,  3,  1,  2,  3],
        [ 1,  2,  3,  1,  2,  3],
        [ 1,  2,  3,  1,  2,  3],
        [ 1,  2,  3,  1,  2,  3]])
>>> x.repeat(4, 2, 1).size()
torch.Size([4, 2, 3])

文件

取得 PyTorch 的完整開發人員文件

檢視文件

教學

取得適合初學者和進階開發人員的深入教學

檢視教學

資源

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

檢視資源