【发布时间】:2021-03-09 19:53:50
【问题描述】:
如何在 Pytorch 中制作张量列表。 该列表应如下所示:
mylist = [tensor1, tensor2, tensor3]
所有张量都有不同的形状
【问题讨论】:
-
好吧,你刚刚做到了。
-
Here 是您正在寻找的解决方案:
标签: python python-3.x pytorch tensor
如何在 Pytorch 中制作张量列表。 该列表应如下所示:
mylist = [tensor1, tensor2, tensor3]
所有张量都有不同的形状
【问题讨论】:
标签: python python-3.x pytorch tensor
您可以使用 pytorch inline 实例化每个张量,也可以在循环中附加到列表中。 内联:
mylist = [torch.rand(2), torch.rand(5), torch.rand(1)]
在循环中:
mylist = [torch.rand(i) for i in range(1, 5)]
要创建自定义张量,例如使用torch.tensor([[1., -1.], [1., -1.]])。
https://pytorch.org/docs/stable/tensors.html
【讨论】: