torch.Tensor.repeat
- 张量.repeat(*repeats) → 张量
-
沿着指定的维度重复这个张量。
与
expand()
不同,该函数会复制张量的数据。警告
repeat()
的行为与 numpy.repeat 不同,但更类似于 numpy.tile。若要使用类似 numpy.repeat 的操作,请参见torch.repeat_interleave()
。示例:
>>> 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])