WarSaw
WarSaw

Reputation: 17

TypeError: can't convert np.ndarray of type numpy.object with CSV file input

I have a google collab project I am making with pytorch and pandas to read a csv file and train it. Here is my code below that does not work.

inputs = ['L', 'A'... etc. many more]
x = torch.tensor(df[inputs].values, dtype=torch.float, device=device)

outputs = ['R', 'S']
y = torch.tensor(df[outputs].values, dtype=torch.float, device=device)

Then here is the error

TypeError                                 Traceback (most recent call last)
<ipython-input-5-853118d63d3d> in <cell line: 4>()
      2 # Extract the inputs and create a pytorch tensor x(inputs)
      3 inputs = ['L', 'A'...
----> 4 x = torch.tensor(df[inputs].values, dtype=torch.float, device=device)
      5 
      6 outputs = ['R', 'S']

TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

I do not quite understand what I am doing wrong. I have a CSV file with all numbers in rows and columns which is what is in the df values.

Upvotes: 1

Views: 255

Answers (0)

Related Questions