def METHOD_NAME(self, dist, cluster_len, i, j):
    # the new cluster i merged from i and j adopts the average of
    # i and j's similarity to each other cluster, weighted by the
    # number of points in the clusters i and j
    i_weight = cluster_len[i]
    j_weight = cluster_len[j]
    weight_sum = i_weight + j_weight
    # update for x<i
    dist[:i, i] = dist[:i, i] * i_weight + dist[:i, j] * j_weight
    dist[:i, i] /= weight_sum
    # update for i<x<j
    dist[i, i + 1 : j] = (
        dist[i, i + 1 : j] * i_weight + dist[i + 1 : j, j] * j_weight
    )
    # update for i<j<x
    dist[i, j + 1 :] = dist[i, j + 1 :] * i_weight + dist[j, j + 1 :] * j_weight
    dist[i, i + 1 :] /= weight_sum