torch.Tensor.repeat¶
- Tensor.repeat(*repeats) Tensor¶
沿指定維度重複此張量。
與
expand()不同,此函式會複製張量的資料。警告
repeat()的行為與 numpy.repeat 不同,但更類似於 numpy.tile。對於類似於 numpy.repeat 的運算子,請參閱torch.repeat_interleave()。- 引數
repeat (torch.Size, int..., tuple 或 list,元素為 int) – 沿每個維度重複此張量的次數
示例
>>> 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])