code: def np_map_fn(
      fn: Callable[[Any], Any],
      slices: Union[list[Any], dict[str, Any], np.ndarray],
  ):
      """Executes fn on all slices. NumPy equivalent of tf.map_fn.
  
      Args:
        fn: The function to execute.
        slices: An iterable or a dict of iterables.
  
      Returns:
        An object with the same structure as `slices` where every slice has `fn`
          applied.
      """
      if isinstance(slices, (list, np.ndarray)):
          return [fn(example) for example in slices]
      elif isinstance(slices, dict):
          if not slices:
              return slices
          if any(tree.is_nested(value) for value in slices.values()):
              raise NotImplementedError(
                  "Nested dict not supported by np_map_fn."
              )
          # For each slice of the dictionary...
          # {             <----- slice1 ----->     <----- slice2 ----->
          #     "image": [b"\x89PNG\r\n\x1a\n...", b"\x89PNG\r\n\x1a\n...", ...]
          #     "shape": [(100, 100, 3),           (100, 100, 3),           ...]
          # }
          # ...we apply the `fn` and reconstruct the dictionary:
          # {
          #     "image": np.array([[[255, 255, 0], ...]], ...])
          #     "shape": [(100, 100, 3),                  ...]
          # }
          fn_slices = [fn(s) for s in _dict_to_list(slices)]
          return _list_to_dict(fn_slices)
      else:
          raise ValueError(
              f"type {type(slices)} is not supported by np_map_fn."
          )
  
file_path: datasets/tensorflow_datasets/core/utils/np_utils.py
imports: from typing import Any, Callable, Tuple, Union
  import numpy
  from tensorflow_datasets.core.utils import py_utils
  from tensorflow_datasets.core.utils import type_utils
  import tree
label_desc: Use image node_id 4 for calling a global function with example usage: np_map_fn(fn, slices) and returns: unknown, _list_to_dict, slices