Returns the k-th nearest distances, row-wise, as a column vector

def kdists(matrix, k=7, ix=None):
    """ Returns the k-th nearest distances, row-wise, as a column vector """

    ix = ix or kindex(matrix, k)
    return matrix[ix][np.newaxis].T