'what's the difference between np.linalg.norm(a-x) and np.linalg.norm(a) - np.linalg.norm(x)?

I am trying to do extract features from an image and then compare these features to an array of features from thousands of images.

image = Image.open('C:/Users/Timmi/Desktop/test_image.jpg')

query = fe.extract(image)
print(np.shape(query))
print(np.linalg.norm(query))

dists = np.linalg.norm(features - query, axis=1)
print(dists)
print(np.shape(features))
dists2 = (np.linalg.norm(features, axis=1)) - (np.linalg.norm(query, 0))
print(dists2)

ids = np.argsort(dists)[:3]
scores = [(dists[id], img_paths[id]) for id in ids]
print(scores)

This is what gets printed

(4096,)
0.99999994
[0.96851873 1.0867099  1.054868   ... 1.2182273  1.2591194  1.2556202 ]
(31303, 4096)
[-1158. -1158. -1158. ... -1158. -1158. -1158.]
[(0.0, WindowsPath('static/img/image1.jpg')), (0.0, WindowsPath('static/img/image2.jpg')), (0.08249867, WindowsPath('static/img/image3.jpg'))]

I trying to find the difference between these two lines:

dists1 = np.linalg.norm(features - query, axis=1)

dists2 = (np.linalg.norm(features, axis=1)) - np.array(np.linalg.norm(query, 0))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source