torch.Tensor.repeat

张量.repeat(*repeats) 张量

沿着指定的维度重复这个张量。

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])
本页目录