(vals, dist_thresh)
return clusters
Very simple clusting in 1D: Sort <vals> and calculate distance between values. Form clusters when <dist_thresh> is
    exceeded.
    
    Returns a list of clusters, where each element in the list is a np.array with indices of <vals>.
Very simple clusting in 1D: Sort <vals> and calculate distance between values. Form clusters when <dist_thresh> is
    exceeded.
    
    Returns a list of clusters, where each element in the list is a np.array with indices of <vals>.
Very simple clusting in 1D : Sort <vals > and calculate distance between values . Form clusters when <dist_thresh > is exceeded . Returns a list of clusters where each element in the list is a np . array with indices of <vals > .
def find_clusters_1d_break_dist(vals, dist_thresh):
    """
    Very simple clusting in 1D: Sort <vals> and calculate distance between values. Form clusters when <dist_thresh> is
    exceeded.
    
    Returns a list of clusters, where each element in the list is a np.array with indices of <vals>.
    """
    if type(vals) is not np.ndarray:
        raise TypeError("vals must be a NumPy array")
    
    if dist_thresh < 0:
        raise ValueError("dist_thresh must be positive")
    
    clusters = []
    
    if len(vals) > 0:
        pos_indices_sorted = np.argsort(vals)      # indices of sorted values
        gaps = np.diff(vals[pos_indices_sorted])   # calculate distance between sorted values
        
        cur_clust = [pos_indices_sorted[0]]  # initialize with first index
        
        if len(vals) > 1:
            for idx, gap in zip(pos_indices_sorted[1:], gaps):
                if gap >= dist_thresh:           # create new cluster
                    clusters.append(np.array(cur_clust))
                    cur_clust = []
                cur_clust.append(idx)
            
        clusters.append(np.array(cur_clust))
    
    assert len(vals) == sum(map(len, clusters))
    
    return clusters
def find_clusters_1d_break_dist ( vals , dist_thresh ) : if type ( vals ) is not np . ndarray : raise TypeError ( "vals must be a NumPy array" ) if dist_thresh < 0 : raise ValueError ( "dist_thresh must be positive" ) clusters = [ ] if len ( vals ) > 0 : pos_indices_sorted = np . argsort ( vals ) # indices of sorted values gaps = np . diff ( vals [ pos_indices_sorted ] ) # calculate distance between sorted values cur_clust = [ pos_indices_sorted [ 0 ] ] # initialize with first index if len ( vals ) > 1 : for idx , gap in zip ( pos_indices_sorted [ 1 : ] , gaps ) : if gap >= dist_thresh : # create new cluster clusters . append ( np . array ( cur_clust ) ) cur_clust = [ ] cur_clust . append ( idx ) clusters . append ( np . array ( cur_clust ) ) assert len ( vals ) == sum ( map ( len , clusters ) ) return clusters