Issue
I have data that I want to setup as a PyTorch tensor as my objective for a ML algorithm. If I inspect the list as is I get :
ydata = [1.39e-11, 1.5e-12, 4.7e-16]
I want to have this list in a tensor, so I tried multiple functions but everytime I get a TypeError for instance :
torch.FloatTensor(ydata) -> TypeError('must be real number, not str')
However if I inspect the type of each element of ydata it is a float. How can I go about getting the data I want into a tensor?
Thank you very much.
Solution
I just tried to replicate your example on my machine:
pip install torch torchvision torchaudio
then:
import torch
ydata = ['1.39e-11', '1.5e-12', '4.7e-16']
ydata = [float(x) for x in ydata] # convert your string to float
torch.FloatTensor(ydata)
#output
tensor([1.3900e-11, 1.5000e-12, 4.7000e-16])
Answered By - Goku - stands with Palestine
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.