How can I convert a tensor into a list of tensors. For instance: P1 is a torch.Tensor with 60 values in it and I want a list of tensors with 60 tensors in it.
How can I convert a tensor into a list of tensors. For instance: P1 is a torch.Tensor with 60 values in it and I want a list of tensors with 60 tensors in it.
You can coerce the torch.Tensor to a list with list:
>>> P1 = torch.rand(60)
>>> list(P1)
[tensor(0.5987),
tensor(0.5321),
tensor(0.6590),
...
tensor(0.1381)]
This works with multi-dimensional tensors too:
>>> P1 = torch.rand(60, 2)
>>> list(P1)
[tensor([0.4675, 0.0430]),
tensor([0.2175, 0.6271]),
tensor([0.3378, 0.8516]),
...,
tensor([0.5099, 0.3411]