-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2_0.py
28 lines (23 loc) · 876 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
'''
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):
i_digits = data.get_digits_by_label(train_data, train_labels, i)
# Compute mean of class i
means.append(np.reshape(np.mean(i_digits, axis=0),(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') # 7000*64 / 4000*64
# print(train_data.shape, train_labels.shape, _.shape)
plot_means(train_data, train_labels)