如何在python中创建pytorch张量列表?



如何在Pytorch中创建张量列表?列表应该是这样的:

mylist = [tensor1, tensor2, tensor3]

所有张量都有不同的形状

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

最新更新