code: def _transform_example(
      example: Example,
      fn: Callable[[Any], Any],
      in_parts: List[str],
      out_parts: List[str],
  ) -> Example:
      """Transforms the specified input entry with `fn`.
  
      Note that the given example data is transformed in place.
  
      Arguments:
        example: the example data that needs to be transformed.
        fn: the function used to transform data.
        in_parts: what feature in the example should be transformed. For example, if
          `in_parts` is `["a", "b"]`, then `fn` will be applied to the nested
          feature `b` inside `a`.
        out_parts: where the transformed data should be stored in the example. Note
          that this needs to be at the same level as `in_parts`. For example, if
          `in_parts=["a", "b", "c"]`, then the output feature needs to be inside
          `["a", "b']`, e.g. `out_parts=["a", "b", "new_feature"]`.
  
      Returns:
        the transformed example.
      """
      if not in_parts:
          raise ValueError(
              "Should be called with non-empty `in_parts`!"
          )
      in_key = in_parts[0]
      out_key = out_parts[0]
      if len(in_parts) > 1:
          in_rest = in_parts[1:]
          out_rest = out_parts[1:]
          if isinstance(example[in_key], np.ndarray) or isinstance(
              example[in_key], list
          ):
              example[out_key] = [
                  _transform_example(
                      example=ex,
                      fn=fn,
                      in_parts=in_rest,
                      out_parts=out_rest,
                  )
                  for ex in example[in_key]
              ]
          else:
              example[out_key] = _transform_example(
                  example=example[in_key],
                  fn=fn,
                  in_parts=in_rest,
                  out_parts=out_rest,
              )
      elif len(in_parts) == 1:
          input_data = example[in_key]
          if isinstance(input_data, List):
              example[out_key] = [fn(x) for x in input_data]
          else:
              example[out_key] = fn(example[in_key])
      return example
  
file_path: datasets/tensorflow_datasets/core/transform/transform_lib.py
imports: from __future__ import annotations
  import functools
  from typing import Any, Callable, Iterator, List, Mapping, Optional, Union
  import numpy
  from tensorflow_datasets.core import split_builder
label_desc: Use image node_id 4 for calling a global function with example usage: _transform_example(example, fn, in_parts, out_parts) and returns: example