例如,我有向量[1, 2, 3]
我想得到一个像这样的矩阵
[[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
[1, 2, 3]]
如何有效地做到这一点?
最佳答案
您应该查看.repeat()
:
In [1]: torch.Tensor([1, 2, 3]).repeat(4, 1)
Out[1]:
tensor([[1., 2., 3.],
[1., 2., 3.],
[1., 2., 3.],
[1., 2., 3.]])
关于machine-learning - 如何将向量转换为矩阵,每行等于pytorch中的向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52144507/