code: def recursive_enumerate_nd(it, stop_iter=None, prefix=()):
      """Recursively enumerate nested iterables with tuples n-dimenional indices.
  
      Args:
        it: object to be enumerated
        stop_iter: User defined funciton which can conditionally block further
          iteration. Defaults to allowing iteration.
        prefix: index prefix (not intended for end users)
  
      Yields:
        (tuple representing n-dimensional index, original iterator value)
  
      Example use:
        it = ((x+y for y in range(10) )
                   for x in range(10) )
        recursive_enumerate_nd(it) # yields things like ((9,9), 18)
  
      Example stop_iter:
        stop_iter = lambda x: isinstance(x, np.ndarray) and len(x.shape) <= 3
        # this prevents iteration into the last three levels (eg. x,y,channels) of
        # a numpy ndarray
  
      """
      if stop_iter is None:
          stop_iter = lambda x: False
  
      for n, x in enumerate(it):
          n_ = prefix + (n,)
          if isinstance(x, Iterable) and (not stop_iter(x)):
              yield from recursive_enumerate_nd(
                  x, stop_iter=stop_iter, prefix=n_
              )
          else:
              yield (n_, x)
  
imports: import itertools
  import types
  from collections.abc import Iterable
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: recursive_enumerate_nd(it, stop_iter, prefix) without return types