code: def __xd_iterator_pass_on(arr, view, fun):
      """
      Like xd_iterator, but the fun return values are always passed on to the next and only the last returned.
      """
      # create list of iterations
      iterations = [
          [None] if dim in view else list(range(arr.shape[dim]))
          for dim in range(arr.ndim)
      ]
  
      # iterate, create slicer, execute function and collect results
      passon = None
      for indices in itertools.product(*iterations):
          slicer = [
              slice(None) if idx is None else slice(idx, idx + 1)
              for idx in indices
          ]
          passon = fun(scipy.squeeze(arr[slicer]), passon)
  
      return passon
  
file_path: medpy/bin/medpy_graphcut_label_bgreduced.py
imports: from argparse import RawTextHelpFormatter
  import argparse
  import logging
  import itertools
  import os
  import scipy
  from scipy import ndimage
  from medpy.core import ArgumentError, Logger
  from medpy.io import load, save
  from medpy import graphcut
  from medpy import filter
  from medpy.graphcut.wrapper import split_marker
label_desc: Use image node_id 3 for calling a global function with example usage: __xd_iterator_pass_on(arr, view, fun) and returns: passon