I am learning Neural Network. I was running following source code

import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
(X_train , y_train) , (X_test , y_test) = keras.datasets.mnist.load_data()

I was searching about keras mnist dataset. I found this. From that webpage I found This is a dataset of 60,000 28x28 grayscale images of the 10 digits, along with a test set of 10,000 images. More info can be found at the MNIST homepage. But, I was trying lot of datas. Finally, I thought to write plt.matshow(X_train[10010])

It outputs : enter image description here

As mnist digits classification were they had test set of 10,000 images. So, over than 10000 should return error. While it is showing more plots. Why?


1 Answer 1


You are actually plotting the train set with X_train which has 60k samples.

Try accessing X_test[10010] and it will indeed raise an IndexError.

keras.datasets.mnist.load_data() returns numpy.array objects, so you can check the shape of the arrays

>>> print("Train:", X_train.shape)
Train: (60000, 28, 28)
>>> print("Test:", X_test.shape)
Test: (10000, 28, 28)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.