expand()
Returns a new view of the :attr:
self
tensor with singleton dimensions expanded to a larger size.
将张量=1
的维度进行扩展,>1
的维度保持不变。
import torch
a = torch.tensor([[12, 3, 4]])
a.expand(3,-1)
tensor([[12, 3, 4],[12, 3, 4],[12, 3, 4]])
repeat()
Repeats this tensor along the specified dimensions.
将张量沿着特定维度进行复制。
b = torch.tensor([[1,2,4],[4,5,6]])
b.repeat(3,2)
tensor([[1, 2, 4, 1, 2, 4],[4, 5, 6, 4, 5, 6],[1, 2, 4, 1, 2, 4],[4, 5, 6, 4, 5, 6],[1, 2, 4, 1, 2, 4],[4, 5, 6, 4, 5, 6]])