評價此頁

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])