code: def fusion(K, pop, i, j, k):
      """Modifies the graph K to merge nodes i and  j into nodes k
  
      The similarity values are weighted averaged, where pop[i] and pop[j]
      yield the relative weights.
      this is used in average_link_slow (deprecated)
      """
      #
      fi = float(pop[i]) / (pop[k])
      fj = 1.0 - fi
      #
      # replace i ny k
      #
      idxi = np.nonzero(K.edges[:, 0] == i)
      K.weights[idxi] = K.weights[idxi] * fi
      K.edges[idxi, 0] = k
      idxi = np.nonzero(K.edges[:, 1] == i)
      K.weights[idxi] = K.weights[idxi] * fi
      K.edges[idxi, 1] = k
      #
      # replace j by k
      #
      idxj = np.nonzero(K.edges[:, 0] == j)
      K.weights[idxj] = K.weights[idxj] * fj
      K.edges[idxj, 0] = k
      idxj = np.nonzero(K.edges[:, 1] == j)
      K.weights[idxj] = K.weights[idxj] * fj
      K.edges[idxj, 1] = k
      #
      # sum/remove double edges
      #
      # left side
      idxk = np.nonzero(K.edges[:, 0] == k)[0]
      corr = K.edges[idxk, 1]
      scorr = np.sort(corr)
      acorr = np.argsort(corr)
      for a in range(np.size(scorr) - 1):
          if scorr[a] == scorr[a + 1]:
              i1 = idxk[acorr[a]]
              i2 = idxk[acorr[a + 1]]
              K.weights[i1] = K.weights[i1] + K.weights[i2]
              K.weights[i2] = -np.inf
              K.edges[i2] = -1
  
      # right side
      idxk = np.nonzero(K.edges[:, 1] == k)[0]
      corr = K.edges[idxk, 0]
      scorr = np.sort(corr)
      acorr = np.argsort(corr)
      for a in range(np.size(scorr) - 1):
          if scorr[a] == scorr[a + 1]:
              i1 = idxk[acorr[a]]
              i2 = idxk[acorr[a + 1]]
              K.weights[i1] = K.weights[i1] + K.weights[i2]
              K.weights[i2] = -np.inf
              K.edges[i2] = -1
  
imports: from warnings import warn
  import numpy
  from ..graph.forest import Forest
  from ..graph.graph import WeightedGraph
label_desc: Use image node_id 1 for calling a global function with example usage: fusion(K, pop, i, j, k) without return types