一般情况下,如果expand和repeat都能得到目标矩阵,则在不更改目标矩阵元素(只读用法)时使用expand, 其他情况时使用repeat....torch.Tensor.repeat
import torch
x = torch.tensor(1, 2,4)
y = x.repeat(3,2)
# In 17: y
# Out17:
# tensor...tensor([1, 2, 4, 1, 2, 4,
# 5, 2, 4, 1, 2, 4,
# 1, 2, 4, 1, 2, 4])
torch.Tensor.repeat