I have a numpy array with shape (291336, 50). i.e. there are 291336 points where each point has 50 dimensions.
For each point in this array, I want to find the distance and index of its k
th nearest neighbor by distance, belonging to the same array. I found this related question, but it finds the 1st
nearest neighbor not the k
th.
I have thought about using this brute force approach-
for i in X.shape[0]:
distance_from_i = {}
for j in X.shape[0]:
store distance & index of j from i in distance_from_i
sort distance_from_i and select the k'th point
But I know it's terrible. There must be a better way.
How do I solve this problem?