problem in binary classification #89
Answered
by
aronvandepol
Sarthak-Singh04
asked this question in
Q&A
-
I don't why they show error when I convert the numpy into tensor I follow the same as You used in the video pls help this line of code send me in trouble # Turn data into tensors
# Otherwise this causes issues with computations later on
import torch
x = torch.from_numpy(X).type(torch.float)
y = torch.from_numpy(y).type(torch.float)
# View the first five samples
x[:5], y[:5]
TypeError Traceback (most recent call last)
[<ipython-input-44-881c02e4b1fd>](https://localhost:8080/#) in <module>()
2 # Otherwise this causes issues with computations later on
3 import torch
----> 4 X = torch.from_numpy(X).type(torch.float)
5 y = torch.from_numpy(y).type(torch.float)
6
TypeError: expected np.ndarray (got Tensor) |
Beta Was this translation helpful? Give feedback.
Answered by
aronvandepol
Aug 8, 2022
Replies: 1 comment 2 replies
-
You are passing a tensor object into a '.from_numpy()' function as it says in the video. The X and likely y variables contain a tensor. '.from_numpy()' needs a ndarray. As the error says. If your code is exactly the same it can be due to incorrect order of jupyter cells, or running it twice. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
mrdbourke
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are passing a tensor object into a '.from_numpy()' function as it says in the video. The X and likely y variables contain a tensor. '.from_numpy()' needs a ndarray. As the error says.
If your code is exactly the same it can be due to incorrect order of jupyter cells, or running it twice.