Converting a list of lists and scalars to a list of PyTorch ...
stackoverflow.com › questions › 63223223Aug 03, 2020 · I was converting a list of lists to a PyTorch tensor and got a warning message. The conversion itself isn't difficult. For example: >>> import torch >>> thing = [ [1, 2, 3, 4, 5], [2, 3], 2, 3] >>> thing_tensor = list (map (torch.tensor, thing)) I get the warning: home/user1/files/module.py:1: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone ().detach () or sourceTensor.clone ().detach ().requires_grad_ (True), rather than torch.tensor (sourceTensor).
python - converting list of tensors to tensors pytorch ...
stackoverflow.com › questions › 55050717Mar 08, 2019 · import torch a = torch.arange (8).reshape (2, 2, 2) b = torch.arange (12).reshape (2, 2, 3) my_list = [a, b] my_tensor = torch.cat ( [a, b], dim=2) print (my_tensor.shape) #torch.Size ( [2, 2, 5]) you haven't explained your goal so another option is to use pad_sequence like this: