Skip to content
Snippets Groups Projects
Commit bf5a1b1c authored by pheithar's avatar pheithar
Browse files

Header fix

parent 9fb05005
No related branches found
No related tags found
No related merge requests found
# exercise 3.3.1 # exercise 2.2.1
import importlib_resources import importlib_resources
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -39,11 +39,13 @@ plt.subplot(3,1,1) ...@@ -39,11 +39,13 @@ plt.subplot(3,1,1)
img_hw = int(np.sqrt(len(X[0]))) img_hw = int(np.sqrt(len(X[0])))
img = np.reshape(X[i], (img_hw, img_hw)) img = np.reshape(X[i], (img_hw, img_hw))
if transpose: img = img.T if transpose:
img = img.T
plt.imshow(img, cmap=plt.cm.gray) plt.imshow(img, cmap=plt.cm.gray)
plt.xticks([]); plt.yticks([]) plt.xticks([])
plt.title('Query image') plt.yticks([])
plt.ylabel('image #{0}'.format(i)) plt.title("Query image")
plt.ylabel("image #{0}".format(i))
for ms in range(5): for ms in range(5):
...@@ -53,25 +55,31 @@ for ms in range(5): ...@@ -53,25 +55,31 @@ for ms in range(5):
im_id = sim_to_index[-ms - 1][1] im_id = sim_to_index[-ms - 1][1]
im_sim = sim_to_index[-ms - 1][0] im_sim = sim_to_index[-ms - 1][0]
img = np.reshape(X[im_id], (img_hw, img_hw)) img = np.reshape(X[im_id], (img_hw, img_hw))
if transpose: img = img.T if transpose:
img = img.T
plt.imshow(img, cmap=plt.cm.gray) plt.imshow(img, cmap=plt.cm.gray)
plt.xlabel('sim={0:.3f}'.format(im_sim)) plt.xlabel("sim={0:.3f}".format(im_sim))
plt.ylabel('image #{0}'.format(im_id)) plt.ylabel("image #{0}".format(im_id))
plt.xticks([]); plt.yticks([]) plt.xticks([])
if ms==2: plt.title('Most similar images') plt.yticks([])
if ms == 2:
plt.title("Most similar images")
# 5 least similar images found # 5 least similar images found
plt.subplot(3, 5, 11 + ms) plt.subplot(3, 5, 11 + ms)
im_id = sim_to_index[ms][1] im_id = sim_to_index[ms][1]
im_sim = sim_to_index[ms][0] im_sim = sim_to_index[ms][0]
img = np.reshape(X[im_id], (img_hw, img_hw)) img = np.reshape(X[im_id], (img_hw, img_hw))
if transpose: img = img.T if transpose:
img = img.T
plt.imshow(img, cmap=plt.cm.gray) plt.imshow(img, cmap=plt.cm.gray)
plt.xlabel('sim={0:.3f}'.format(im_sim)) plt.xlabel("sim={0:.3f}".format(im_sim))
plt.ylabel('image #{0}'.format(im_id)) plt.ylabel("image #{0}".format(im_id))
plt.xticks([]); plt.yticks([]) plt.xticks([])
if ms==2: plt.title('Least similar images') plt.yticks([])
if ms == 2:
plt.title("Least similar images")
plt.show() plt.show()
print('Ran Exercise 2.2.1') print("Ran Exercise 2.2.1")
# exercise 3.2.2 # exercise 2.2.2
import numpy as np import numpy as np
......
# exercise 3.1.4 # exercise 3.1.4
# (requires data structures from ex. 2.2.1 and 2.2.3) # (requires data structures from ex. 3.1.1)
from ex3_1_1 import * from ex3_1_1 import *
from matplotlib.pyplot import figure, legend, plot, show, title, xlabel, ylabel from matplotlib.pyplot import figure, legend, plot, show, title, xlabel, ylabel
from scipy.linalg import svd from scipy.linalg import svd
......
# exercise 3.1.5 # exercise 3.1.5
# (requires data structures from ex. 2.2.1) # (requires data structures from ex. 3.1.1)
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from ex3_1_1 import * from ex3_1_1 import *
from scipy.linalg import svd from scipy.linalg import svd
......
...@@ -28,5 +28,3 @@ plot(X, ".") ...@@ -28,5 +28,3 @@ plot(X, ".")
subplot(1, 3, 3) subplot(1, 3, 3)
hist(X, bins=nbins) hist(X, bins=nbins)
show() show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment