code: def mst(X):
      """Returns the WeightedGraph that is the minimum Spanning Tree of X
  
      Parameters
      ----------
      X: data array, of shape(n_samples, n_features)
  
      Returns
      -------
      the corresponding WeightedGraph instance
      """
      n = X.shape[0]
      label = np.arange(n).astype(np.int_)
  
      edges = np.zeros((0, 2)).astype(np.int_)
      # upper bound on maxdist**2
      maxdist = 4 * np.sum((X - X[0]) ** 2, 1).max()
      nbcc = n
      while nbcc > 1:
          mindist = maxdist * np.ones(nbcc)
          link = -np.ones((nbcc, 2)).astype(np.int_)
  
          # find nearest neighbors
          for n1 in range(n):
              j = label[n1]
              newdist = np.sum((X[n1] - X) ** 2, 1)
              newdist[label == j] = maxdist
              n2 = np.argmin(newdist)
              if newdist[n2] < mindist[j]:
                  mindist[j] = newdist[n2]
                  link[j] = np.array([n1, n2])
  
          # merge nearest neighbors
          nnbcc = nbcc
          idx = np.arange(nbcc)
          for i in range(nnbcc):
              k, j = label[link[i]]
              while k > idx[k]:
                  k = idx[k]
              while j > idx[j]:
                  j = idx[j]
              if k != j:
                  edges = np.vstack(
                      (
                          edges,
                          link[i],
                          np.array([link[i, 1], link[i, 0]]),
                      )
                  )
              idx[max(j, k)] = min(j, k)
              nbcc -= 1
          # relabel the graph
          label = WeightedGraph(n, edges, np.ones(edges.shape[0])).cc()
          nbcc = label.max() + 1
  
      d = np.sqrt(np.sum((X[edges[:, 0]] - X[edges[:, 1]]) ** 2, 1))
      return WeightedGraph(n, edges, d)
  
imports: import numpy
  from scipy.sparse import coo_matrix
label_desc: Use image node_id 4 for calling a global function with example usage: mst(X) and returns: WeightedGraph