Skip to content

Instantly share code, notes, and snippets.

@mjbhobe
Created September 27, 2018 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjbhobe/648812b4fabadc044fd195252936e155 to your computer and use it in GitHub Desktop.
Save mjbhobe/648812b4fabadc044fd195252936e155 to your computer and use it in GitHub Desktop.
from keras.datasets.mnist import load_data
# load the data - it returns 2 tuples of digits & labels - one for
# the train set & the other for the test set
(train_digits, train_labels), (test_digits, test_labels) = load_data()
# display 14 random images from the training set
import numpy as np
np.random.seed(123)
rand_14 = np.random.randint(0, train_digits.shape[0],14)
sample_digits = train_digits[rand_14]
sample_labels = train_labels[rand_14]
# code to view the images
num_rows, num_cols = 2, 7
f, ax = plt.subplots(num_rows, num_cols, figsize=(12,5),
gridspec_kw={'wspace':0.03, 'hspace':0.01},
squeeze=True)
for r in range(num_rows):
for c in range(num_cols):
image_index = r * 7 + c
ax[r,c].axis("off")
ax[r,c].imshow(sample_digits[image_index], cmap='gray')
ax[r,c].set_title('No. %d' % sample_labels[image_index])
plt.show()
plt.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment