In [1]:
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
digits = datasets.load_digits()

In [3]:
print(digits.data.shape)
print(digits.images.shape)


(1797, 64)
(1797, 8, 8)

In [4]:
img = digits.images[0, :, :]

In [5]:
plt.imshow(img, cmap='gray')


Out[5]:
<matplotlib.image.AxesImage at 0x1ef0a5dff28>

In [6]:
for image_index in range(10):
    # images are 0-indexed, but subplots are 1-indexed
    subplot_index = image_index + 1
    plt.subplot(2, 5, subplot_index)
    plt.imshow(digits.images[image_index, :, :],\
              cmap='gray')



In [ ]: