Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running the example cnn_mnist.py and mlp_mnist.py #5

Open
Zehui127 opened this issue Jun 4, 2017 · 3 comments
Open

Error when running the example cnn_mnist.py and mlp_mnist.py #5

Zehui127 opened this issue Jun 4, 2017 · 3 comments

Comments

@Zehui127
Copy link

Zehui127 commented Jun 4, 2017

Thanks for your great work
I found some problem when running the example, I can't find the reason
when running the above two example, the following error pop up:

Traceback (most recent call last):
File "cnn_mnist.py", line 72, in
run()
File "cnn_mnist.py", line 62, in run
nn.fit(X_train, y_train, learning_rate=0.05, max_iter=3, batch_size=32)
File "F:\summerVacation\lib\site-packages\nnet\neuralnetwork.py", line 29, in fit
Y_one_hot = one_hot(Y)
File "F:\summerVacation\lib\site-packages\nnet\helpers.py", line 9, in one_hot
one_hot_labels[labels == c, c] = 1
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

I'm not sure why this happen.

@iamyup
Copy link

iamyup commented Jun 14, 2017

Hi,

I also have same problem. no one find the solution ?

@snowkylin
Copy link

@Zehui127 @iamyup In cnn_mnist.py and mlp_mnist.py, The type of y_train and y_test need to be converted to int, since the index of array cannot be float. i.e., modify the code
y_train = mnist.target[:split]
y_test = mnist.target[split:]
to
y_train = mnist.target[:split].astype("int")
y_test = mnist.target[split:].astype("int")

@abhinav0491
Copy link

@snowkylin I tried the solution you provided, but Im still getting the same error.

Traceback (most recent call last):
File "cnn_mnist.py", line 72, in
run()
File "cnn_mnist.py", line 62, in run
nn.fit(X_train, y_train, learning_rate=0.05, max_iter=3, batch_size=32)
File "/home/abhinav/Testing/nnet-master/nnet/neuralnetwork.py", line 29, in fit
Y_one_hot = one_hot(Y)
File "/home/abhinav/Testing/nnet-master/nnet/helpers.py", line 9, in one_hot
one_hot_labels[labels == c, c] = 1
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants