code: def as_numpy(dataset: Tree[TensorflowElem]) -> Tree[NumpyElem]:
      """Converts a `tf.data.Dataset` to an iterable of NumPy arrays.
  
      `as_numpy` converts a possibly nested structure of `tf.data.Dataset`s
      and `tf.Tensor`s to iterables of NumPy arrays and NumPy arrays, respectively.
  
      Note that because TensorFlow has support for ragged tensors and NumPy has
      no equivalent representation,
      [`tf.RaggedTensor`s](https://www.tensorflow.org/api_docs/python/tf/RaggedTensor)
      are left as-is for the user to deal with them (e.g. using `to_list()`).
      In TF 1 (i.e. graph mode), `tf.RaggedTensor`s are returned as
      `tf.ragged.RaggedTensorValue`s.
  
      Example:
  
      ```
      ds = tfds.load(name="mnist", split="train")
      ds_numpy = tfds.as_numpy(ds)  # Convert `tf.data.Dataset` to Python generator
      for ex in ds_numpy:
        # `{'image': np.array(shape=(28, 28, 1)), 'labels': np.array(shape=())}`
        print(ex)
      ```
  
      Args:
        dataset: a possibly nested structure of `tf.data.Dataset`s and/or
          `tf.Tensor`s.
  
      Returns:
        A structure matching `dataset` where `tf.data.Dataset`s are converted to
        generators of NumPy arrays and `tf.Tensor`s are converted to NumPy arrays.
      """
      _assert_ds_types(dataset)
      if tf.executing_eagerly():
          return tree_utils.map_structure(_elem_to_numpy_eager, dataset)
      else:
          return _nested_to_numpy_graph(dataset)
  
imports: from __future__ import annotations
  import collections.abc
  import functools
  import typing
  from typing import Any, Callable, Iterable, Iterator, Union
  from etils import enp
  from etils.etree import nest
  import numpy
  from tensorflow_datasets.core import logging
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils import tree_utils
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 6 for calling a global function with example usage: as_numpy(dataset) and returns: tree_utils, _nested_to_numpy_graph