评价此页

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