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