code: def relabel_map(label_image, mapping, key=lambda x, y: x[y]):
      r    
      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)
docs: 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