Converting python list to pytorch tensor - Stack Overflow
stackoverflow.com › questions › 60090093Feb 06, 2020 · You can directly convert python list to a pytorch Tensor by defining the dtype. For example, import torch a_list = [3,23,53,32,53] a_tensor = torch.Tensor (a_list) print (a_tensor.int ()) >>> tensor ( [3,23,53,32,53]) Share answered Jan 10 '21 at 2:45 Devanshi 61 1 4 Add a comment 3
torch.Tensor.tolist — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.Tensor.tolist — PyTorch 1.10.0 documentation torch.Tensor.tolist Tensor.tolist() → list or number Returns the tensor as a (nested) list. For scalars, a standard Python number is returned, just like with item () . Tensors are automatically moved to the CPU first if necessary. This operation is not differentiable. Examples: