def _knn(self, i, X, high_dim=True):
        """Performs KNN search based on high/low-dimensional similarity/distance measurement"""

        knns = []
        for j in range(X.shape[0]):
            if j != i:
                if high_dim:
                    distance = self._high_dim_sim(X[i], X[j], idx=i)
                else:
                    distance = self._low_dim_sim(X[i], X[j])
                knns.append([j, distance])

        return sorted(knns, key=lambda x: x[1])[:self.perplexity]
Performs KNN search based on high/low-dimensional similarity/distance measurement