How to convert a list or numpy array to a 1d torch tensor?

后端 未结 1 1265
Happy的楠姐
Happy的楠姐 2021-02-13 13:03

I have a list (or, a numpy array) of float values. I want to create a 1d torch tensor that will contain all those values. I can create the torch tensor and run a loop to store t

相关标签:
1条回答
  • 2021-02-13 13:27

    These are general operations in pytorch and available in the documentation. PyTorch allows easy interfacing with numpy. There is a method called from_numpy and the documentation is available here

    import numpy as np 
    import torch 
    array = np.arange(1, 11)
    tensor = torch.from_numpy(array)
    
    0 讨论(0)
提交回复
热议问题