3030a0b50cc7b19142d6c1ca9b570e6c706e96b7
[handwriting-recognition.git] / read_display_mnist.py
1 #!/usr/bin/python3
2
3 import numpy as np
4 import matplotlib.pyplot as plt
5
6 import mnist
7
8 train_images, train_labels, rows, cols = mnist.load('train-images-idx3-ubyte', 'train-labels-idx1-ubyte')
9
10 # show the first bunch of training data
11 for i in range(10):
12     print(f'train image #{i}: label {train_labels[i]}')
13     plt.imshow(train_images[:, i].reshape(rows, cols), cmap='gray')
14     plt.show()