Shortcuts

torch.Tensor.repeat

Tensor.repeat(*sizes) 张量

沿指定维度重复此张量。

expand()不同,此函数复制张量的数据。

警告

repeat() 的行为与 numpy.repeat 不同,但更类似于 numpy.tile。 对于类似于 numpy.repeat 的操作符,请参见 torch.repeat_interleave()

Parameters

sizes (torch.Sizeint...) – 沿每个维度重复此张量的次数

示例:

>>> 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])
优云智算