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