Skip to content
Snippets Groups Projects
Commit bfd24fdb authored by oscarchaufour's avatar oscarchaufour
Browse files

Update knn.py

parent e5a25f27
No related branches found
No related tags found
No related merge requests found
...@@ -15,12 +15,9 @@ from tqdm import tqdm ...@@ -15,12 +15,9 @@ from tqdm import tqdm
def distance_matrix(A,B) : def distance_matrix(A,B) :
sum_of_squaresA= np.sum(A**2, axis = 1, keepdims = True) sum_of_squaresA= np.sum(A**2, axis = 1, keepdims = True)
sum_of_squaresB = np.sum(B**2, axis = 1) sum_of_squaresB = np.sum(B**2, axis = 1)
# sum_of_squaresA = np.tile(sum_of_squaresAVect, (np.shape(B)[0], 1))
# sum_of_squaresB = np.tile(sum_of_squaresBVect, (np.shape(A)[0], 1))
# Calculate the dot product between the two matrices # Calculate the dot product between the two matrices
dot_product = np.dot(A, B.T) dot_product = np.dot(A, B.T)
# dot_product = np.einsum('ij,jk', A, B.T)
# Calculate the Euclidean distance matrix using the hint provided # Calculate the Euclidean distance matrix using the hint provided
dists = np.sqrt(sum_of_squaresA + sum_of_squaresB - 2 * dot_product) dists = np.sqrt(sum_of_squaresA + sum_of_squaresB - 2 * dot_product)
return dists return dists
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment