Skip to content

Commit 8507ae5

Browse files
committed
Added 10 by 10 array of MNIST digits
1 parent dfc5e27 commit 8507ae5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

fig/chap3/mnist.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
def main():
2323
training_set, validation_set, test_set = load_data()
24-
images = get_images(training_set)
25-
plot_mnist_digit(images[0])
24+
images = get_images(training_set)[:100]
25+
plot_10_by_10_images(images)
2626

2727
#### Plotting
2828
def plot_images_together(images):
@@ -38,6 +38,21 @@ def plot_images_together(images):
3838
plt.yticks(np.array([]))
3939
plt.show()
4040

41+
def plot_10_by_10_images(images):
42+
""" Plot 100 MNIST images in a 10 by 10 table. Note that we crop
43+
the images so that they appear reasonably close together. The
44+
image is post-processed to give the appearance of being continued."""
45+
fig = plt.figure()
46+
images = [image[3:25, 3:25] for image in images]
47+
#image = np.concatenate(images, axis=1)
48+
for x in range(10):
49+
for y in range(10):
50+
ax = fig.add_subplot(10, 10, 10*y+x)
51+
ax.matshow(images[10*y+x], cmap = matplotlib.cm.binary)
52+
plt.xticks(np.array([]))
53+
plt.yticks(np.array([]))
54+
plt.show()
55+
4156
def plot_images_separately(images):
4257
"Plot the six MNIST images separately."
4358
fig = plt.figure()
@@ -115,9 +130,9 @@ def load_data():
115130
return (training_set, validation_set, test_set)
116131

117132
def get_images(training_set):
118-
""" Return a list containing the first six images from the MNIST
133+
""" Return a list containing the first 100 images from the MNIST
119134
data set. Each image is represented as a 2-d numpy array."""
120-
flattened_images = training_set[0][:6]
135+
flattened_images = training_set[0][:100]
121136
return [np.reshape(f, (-1, 28)) for f in flattened_images]
122137

123138
#### Main

fig/chap3/mnist_100_digits.png

56.7 KB
Loading

0 commit comments

Comments
 (0)