【问题标题】:How to make a list of pytorch tensors in python?如何在python中制作pytorch张量列表?
【发布时间】:2021-03-09 19:53:50
【问题描述】:

如何在 Pytorch 中制作张量列表。 该列表应如下所示:

mylist = [tensor1, tensor2, tensor3]

所有张量都有不同的形状

【问题讨论】:

  • 好吧,你刚刚做到了。
  • Here 是您正在寻找的解决方案:

标签: python python-3.x pytorch tensor


【解决方案1】:

您可以使用 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

【讨论】:

    猜你喜欢
    • 2021-05-24
    • 2019-05-23
    • 2022-01-10
    • 2019-08-07
    • 2022-01-01
    • 2019-07-29
    • 2020-08-05
    • 2022-10-17
    相关资源
    最近更新 更多