def query(self, x, k=1, p=None, is_distance=True):
        if not isinstance(x, np.ndarray) or x.shape != (1,self.data.shape[1]):
            x = np.array(x).reshape(1,self.data.shape[1])
        # check the input
        #assert x.shape[1] == self.data.shape[1]
        #assert isinstance(k,int) and k > 0
        
        #if len(x.shape) == 1:
        #    x = x.reshape(1,)
            
        if p == None:
            p = self.p
            is_distance = self.is_distance
            
        # compute the distances between the input points and output points
        if p==np.inf or (isinstance(p,float) or isinstance(p,int)) and p >= 1.0:
            is_distance = True
            dist = PNorm(self.p)
        elif p == "Correlation":
            is_distance = False
            dist = correlation()
        elif p == "Euclidean":
            is_distance = True
            dist = PNorm(2)
        elif p == "Manhattan":
            is_distance = True
            dist = PNorm(1)
        else:
            dist = p #assume p is a user defined function
            
            
        # find the distance matrix between points
        dist_mat = dist(x,self.data).flatten()
        
        # set the index matrix
        dist_sort = np.argsort(dist_mat)
        if not is_distance:
            dist_sort = np.fliplr(dist_sort)
            
        dist_mat  = dist_mat[dist_sort] 

        if isinstance(k, int):
            dist_sort = dist_sort[:k]
            dist_mat = dist_mat[:k]
        else:
            i = dist_mat.searchsorted(k, side='right')
            dist_sort = dist_sort[:i]
            dist_mat = dist_mat[:i]
            
        return dist_mat,dist_sort
Query the instance for nearest neighbors
dataset/ETHPy150Open bolme/pyvision/src/pyvision/ml/knn.py/KNearestNeighbors.query