Skip to content
Snippets Groups Projects
Commit 69c44ac4 authored by Audard Lucile's avatar Audard Lucile
Browse files

Create knn.py

parent 7cb02fb3
No related merge requests found
knn.py 0 → 100644
import numpy as np
def distance_matrix(mat1, mat2):
dists = np.sqrt(np.matmul(mat1, mat1)+ np.matmul(mat2, mat2) - 2 * np.matmul(mat1, mat2))
return dists
def knn_predict(dists, labels_train, k):
return predicted_labels
mat1 = np.array([[1, 2],
[3, 4]])
mat2 = np.array([[5, 6],
[7, 8]])
A = np.matmul(mat1, mat1)
print(A)
B = np.matmul(mat2, mat2)
print(B)
C = 2 * np.matmul(mat1, mat2)
print(C)
print(A + B - C)
mat = distance_matrix(mat1, mat2)
print(mat)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment