python_data_scien/algorithmic_thinking2/project3/alg_project3_solution.py
def hierarchical_clustering(cluster_list, cluster_num_k):
    """
    Compute a hierarchical clustering of a set of clusters
    Note: the function may mutate cluster_list
    
    Input: List of clusters, integer number of clusters
    Output: List of clusters whose length is num_clusters
    """
    while len(cluster_list) > cluster_num_k:
        cluster_list.sort(key = lambda cluster: cluster.horiz_center())
        cp_tuple = fast_closest_pair(cluster_list)
        #cp_tuple = slow_closest_pair(cluster_list)
        idx_i = cp_tuple[1]
        idx_j = cp_tuple[2]
        new_cluster = cluster_list[idx_i].merge_clusters(cluster_list[idx_j])
        cluster_list.pop(idx_i)
        cluster_list.pop(idx_j-1)
        cluster_list.append(new_cluster)
    return cluster_list

    Compute a hierarchical clustering of a set of clusters
    Note: the function may mutate cluster_list
    
    Input: List of clusters, integer number of clusters
    Output: List of clusters whose length is num_clusters
    
Compute a hierarchical clustering of a set of clusters
Note: the function may mutate cluster_list

List of clusters, integer number of clusters
Output: List of clusters whose length is num_clusters
Compute a hierarchical clustering of a set of clusters Note : the function may mutate cluster_list List of clusters integer number of clusters Output : List of clusters whose length is num_clusters
def hierarchical_clustering(cluster_list, cluster_num_k):
    while len(cluster_list) > cluster_num_k:
        cluster_list.sort(key = lambda cluster: cluster.horiz_center())
        cp_tuple = fast_closest_pair(cluster_list)
        idx_i = cp_tuple[1]
        idx_j = cp_tuple[2]
        new_cluster = cluster_list[idx_i].merge_clusters(cluster_list[idx_j])
        cluster_list.pop(idx_i)
        cluster_list.pop(idx_j-1)
        cluster_list.append(new_cluster)
    return cluster_list
def hierarchical_clustering ( cluster_list , cluster_num_k ) : while len ( cluster_list ) > cluster_num_k : cluster_list . sort ( key = lambda cluster : cluster . horiz_center ( ) ) cp_tuple = fast_closest_pair ( cluster_list ) idx_i = cp_tuple [ 1 ] idx_j = cp_tuple [ 2 ] new_cluster = cluster_list [ idx_i ] . merge_clusters ( cluster_list [ idx_j ] ) cluster_list . pop ( idx_i ) cluster_list . pop ( idx_j - 1 ) cluster_list . append ( new_cluster ) return cluster_list
Compute a hierarchical clustering of a set of clusters
Note: the function may mutate cluster_list
Compute a hierarchical clustering of a set of clusters Note : the function may mutate cluster_list
"""
    Compute a hierarchical clustering of a set of clusters
    Note: the function may mutate cluster_list
    
    Input: List of clusters, integer number of clusters
    Output: List of clusters whose length is num_clusters
    """ #cp_tuple = slow_closest_pair(cluster_list)

cluster_list
cluster_num_k