code: def relabel_map(label_image, mapping, key=lambda x, y: x[y]):
      r"""
      Relabel an image using the supplied mapping.
  
      The ``mapping`` can be any kind of subscriptable object. The respective region id is used
      to access the new value from the ``mapping``. The ``key`` keyword parameter can be used to
      supply another access function. The ``key`` function must have the signature
      key(mapping, region-id) and return the new region-id to assign.
  
      Parameters
      ----------
      label_image : array_like
          A nD label map.
      mapping : dictionary or subscriptable object
          A mapping object.
      key : function
          Can be used to defined the key-access to the ``mapping`` object.
  
      Returns
      -------
      relabel_map : ndarray
          A label map with new region ids.
  
      Raises
      ------
      ArgumentError
          If a region id is missing in the supplied mapping
      """
      label_image = scipy.array(label_image)
  
      def _map(x):
          try:
              return key(mapping, x)
          except Exception as e:
              raise ArgumentError(
                  "No conversion for region id {} found in the supplied mapping. Error: {}".format(
                      x, e
                  )
              )
  
      vmap = scipy.vectorize(_map, otypes=[label_image.dtype])
  
      return vmap(label_image)
  
imports: import scipy
  from ..core.exceptions import ArgumentError
label_desc: Use image node_id 1 for calling a global function with example usage: relabel_map(label_image, mapping, key) and returns: vmap, key