code: def expand_indices(
      arr: np.array,
      indices: Union[
          int, Sequence[int], Tuple[np.array], Tuple[slice, ...]
      ],  # Alt. Union[int, Sequence[int], Tuple[Any], Tuple[Any], Tuple[slice]]
      indexed_axes: Sequence[int],
  ) -> Tuple:
      """
      Expands indices to fit array shape. Returns expanded indices.
          --> if indices are a sequence of ints, they are interpreted as indices to the flattened arr,
              and subsequently expanded
          --> if indices contains only slices and 1D sequences for arr, everything is interpreted as slices
          --> if indices contains already expanded indices, they are returned as is
  
      Parameters
      ----------
      arr: np.ndarray
          The input to the expanded.
      indices: int, sequence, tuple
          A list of indices.
      indexed_axes: sequence
          Refers to all axes that are not indexed by slice(None).
  
      Returns
      -------
      tuple
          Expanded indices.
      """
      # TODO: Adapt for batched processing.
  
      # Handle indexed_axes.
      indexed_axes = np.sort(np.array(indexed_axes))
      asserts.assert_indexed_axes(arr, indexed_axes)
  
      # Handle indices.
      if isinstance(indices, int):
          expanded_indices: Union[np.ndarray, tuple, list] = [indices]
      else:
          expanded_indices = []
          for i, idx in enumerate(indices):
              if isinstance(idx, slice) and idx == slice(None):
                  pass
              elif isinstance(idx, slice):
                  start = idx.start
                  end = idx.stop
                  step = idx.step
                  tmp = np.arange(start, end, step)
                  expanded_indices.append(tmp)
              elif isinstance(idx, np.ndarray):
                  expanded_indices.append(idx)
              else:
                  try:
                      expanded_indices.append(int(idx))
                  except:
                      raise ValueError("Unsupported type of indices.")
  
      # Check if unraveling is needed.
      if np.all([isinstance(idx, int) for idx in expanded_indices]):
          expanded_indices = np.unravel_index(
              expanded_indices,
              tuple([arr.shape[i] for i in indexed_axes]),
          )
      elif not np.all(
          [
              isinstance(idx, np.ndarray)
              and idx.ndim == len(expanded_indices)
              for idx in expanded_indices
          ]
      ):
          # Meshgrid sliced axes to account for correct slicing. Correct switched first two axes by meshgrid
          expanded_indices = [
              np.swapaxes(idx, 0, 1) if idx.ndim > 1 else idx
              for idx in np.meshgrid(*expanded_indices)
          ]
  
      # Handle case of 1D indices.
      if np.all([isinstance(idx, int) for idx in expanded_indices]):
          expanded_indices = [np.array(expanded_indices)]
  
      # Cast to list so item assignment works.
      expanded_indices = list(expanded_indices)
  
      assert isinstance(indexed_axes, np.ndarray)
      if indexed_axes.size != len(expanded_indices):
          raise ValueError(
              "indices dimension doesn't match indexed_axes"
          )
  
      # Ensure array dimensions are kept when indexing.
      # Expands dimensions of each element in expanded_indices depending on the number of elements.
      # assert isinstance(expanded_indices, np.ndarray)
      for i in range(len(expanded_indices)):
          if expanded_indices[i].ndim != len(expanded_indices):
              expanded_indices[i] = np.expand_dims(
                  expanded_indices[i],
                  axis=tuple(
                      range(
                          len(expanded_indices)
                          - expanded_indices[i].ndim
                      )
                  ),
              )
  
      # Buffer with None-slices if indices index the last axes.
      for i in range(0, indexed_axes[0]):
          expanded_indices = slice(None), *expanded_indices
  
      return tuple(expanded_indices)
  
imports: import copy
  import re
  from importlib import util
  from typing import Any, Dict, Optional, Sequence, Tuple, Union, List, TypeVar
  import numpy
  from skimage.segmentation import slic, felzenszwalb
  from quantus.helpers import asserts
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 18 for calling a global function with example usage: expand_indices(arr, indices, indexed_axes) and returns: tuple