How do I make a list of tensors in Pytorch. The list should look like this:
mylist = [tensor1, tensor2, tensor3]
where all the tensors have different shapes
How do I make a list of tensors in Pytorch. The list should look like this:
mylist = [tensor1, tensor2, tensor3]
where all the tensors have different shapes
You can instantiate each tensor using pytorch inline or append to a list in a loop. Inline:
mylist = [torch.rand(2), torch.rand(5), torch.rand(1)]
In a loop:
mylist = [torch.rand(i) for i in range(1, 5)]
To create a custom tensor, use torch.tensor([[1., -1.], [1., -1.]])
for example.
https://pytorch.org/docs/stable/tensors.html