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