-
Notifications
You must be signed in to change notification settings - Fork 0
/
q2_0.py
29 lines (24 loc) · 834 Bytes
/
q2_0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''
Question 2.0 Skeleton Code
Here you should load the data and plot
the means for each of the digit classes.
'''
import data
import numpy as np
# Import pyplot - plt.imshow is useful!
import matplotlib.pyplot as plt
def plot_means(train_data, train_labels):
means = []
for i in range(0, 10):
mean_i = []
i_digits = data.get_digits_by_label(train_data, train_labels, i)
# Compute mean of class i
mean_temp = i_digits.mean(0)
means.append(mean_temp.reshape(8, 8))
# Plot all means on same axis
all_concat = np.concatenate(means, 1)
plt.imshow(all_concat, cmap='gray')
plt.show()
if __name__ == '__main__':
train_data, train_labels, _, _ = data.load_all_data_from_zip('a2digits.zip', 'data')
plot_means(train_data, train_labels)