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])
Best way to convert a list to a tensor? - PyTorch Forums
discuss.pytorch.org › t › best-way-to-convert-a-listNov 04, 2019 · DN] -> tensor([D1, D2, ..., DN) :return: nested list D """ # base case, if the current list is not nested anymore, make it into tensor if type(lst[0]) != list: if type(lst) == torch.Tensor: return lst elif type(lst[0]) == torch.Tensor: return torch.stack(lst, dim=0) else: # if the elements of lst are floats or something like that return torch.tensor(lst) current_dimension_i = len(lst) for d_i in range(current_dimension_i): tensor = tensorify(lst[d_i]) lst[d_i] = tensor # end of loop lst[d_i ...