import torch
from torch import nn
from torch.autograd import Variable
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
xy = pd.read_csv("all.csv",names=['pm2.5','pm10,s02','no2','co','o3','tem','hig_tem','low_tem','rain','qiya','shidu','zuixiaoshidu','fengsu_10min','fengsu','rizuidafengsu','rizhao'])
x_data = xy.iloc[6:-1,:-1].values
y_data = xy.iloc[:6,:-1].values
x_data = Variable(torch.from_numpy(x_data))
y_data = Variable(torch.from_numpy(y_data))
.....
I want to run an RNN but i can’t solve the data problem . Then i got an error:
RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.
Seeing floats doesn’t necessarily mean it is a float. What does x_data.dtype return? Try and explicitly cast x_data as a type. x_data.astype(dtype = 'float32)
basically you need to remove all the rows that contain #value!. the data set you are using doesn’t contain only numbers as I expected. Once you have removed these values it should work. Also try and make sense of the error messages… sometimes they are not very helpful but in this case it is.
RuntimeError: can't convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.
Could you please print np.unique(x_data) before passing it to the tensor constructor?
As @Tank explained there seem to be some invalid values in your array.
you probably have some sort of nan value or empty string e.g. ’ ’ somewhere. Trying np.unique() on each column or row of the dataset might help you narrow down the problem.