code: def _hc_cut(n_clusters, children, n_leaves):
      """Function cutting the ward tree for a given number of clusters.
  
      Parameters
      ----------
      n_clusters : int or ndarray
          The number of clusters to form.
  
      children : 2D array, shape (n_nodes-1, 2)
          The children of each non-leaf node. Values less than `n_samples`
          correspond to leaves of the tree which are the original samples.
          A node `i` greater than or equal to `n_samples` is a non-leaf
          node and has children `children_[i - n_samples]`. Alternatively
          at the i-th iteration, children[i][0] and children[i][1]
          are merged to form node `n_samples + i`
  
      n_leaves : int
          Number of leaves of the tree.
  
      Returns
      -------
      labels : array [n_samples]
          cluster labels for each point
  
      """
      if n_clusters > n_leaves:
          raise ValueError(
              "Cannot extract more clusters than samples: "
              "%s clusters where given for a tree with %s leaves."
              % (n_clusters, n_leaves)
          )
      # In this function, we store nodes as a heap to avoid recomputing
      # the max of the nodes: the first element is always the smallest
      # We use negated indices as heaps work on smallest elements, and we
      # are interested in largest elements
      # children[-1] is the root of the tree
      nodes = [-(max(children[-1]) + 1)]
      for i in xrange(n_clusters - 1):
          # As we have a heap, nodes[0] is the smallest element
          these_children = children[-nodes[0] - n_leaves]
          # Insert the 2 children and remove the largest node
          heappush(nodes, -these_children[0])
          heappushpop(nodes, -these_children[1])
      label = np.zeros(n_leaves, dtype=np.intp)
      for i, node in enumerate(nodes):
          label[
              _hierarchical._hc_get_descendent(
                  -node, children, n_leaves
              )
          ] = i
      return label
  
imports: from heapq import heapify, heappop, heappush, heappushpop
  import warnings
  import numpy
  from scipy import sparse
  from ..base import BaseEstimator, ClusterMixin
  from ..externals.joblib import Memory
  from ..externals import six
  from ..metrics.pairwise import paired_distances, pairwise_distances
  from ..utils import check_array
  from ..utils.sparsetools import connected_components
  from .None import _hierarchical
  from ._feature_agglomeration import AgglomerationTransform
  from ..utils.fast_dict import IntFloatDict
  from ..externals.six.moves import xrange
label_desc: Use image node_id 6 for calling a global function with example usage: _hc_cut(n_clusters, children, n_leaves) and returns: label