0

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 kth nearest neighbor by distance, belonging to the same array. I found this related question, but it finds the 1st nearest neighbor not the kth.

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?

RodrikTheReader
  • 757
  • 1
  • 9
  • 22

1 Answers1

0

What about sorting them once by distance from np.zeros(50)

krayyem
  • 39
  • 1
  • 6