I have a n-dimensional vector and I want to find its k nearest neighbors in a list of n-dimensional vectors using euclidian distance.
I wrote the following code (with k=10) which works but runs too slowly and I was wondering if there was a more optimal solution.
def nearest_neighbors(value, array, nbr_neighbors=1):
return np.argsort(np.array([np.linalg.norm(value-x) for x in array]))[:nbr_neighbors]