torch.Tensor.repeat#
- Tensor.repeat(*repeats) Tensor#
沿指定维度重复此张量。
与
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])