code: def extract_random_example_array(
      image_list, example_size=[1, 64, 64], n_examples=1
  ):
      """Randomly extract training examples from image (and a corresponding label).
          Returns an image example array and the corresponding label array.
  
      Args:
          image_list (np.ndarray or list or tuple): image(s) to extract random
              patches from
          example_size (list or tuple): shape of the patches to extract
          n_examples (int): number of patches to extract in total
  
      Returns:
          np.ndarray, np.ndarray: class-balanced patches extracted from full
          images with the shape [batch, example_size..., image_channels]
      """
  
      assert n_examples > 0
  
      was_singular = False
      if isinstance(image_list, np.ndarray):
          image_list = [image_list]
          was_singular = True
  
      assert all(
          [
              i_s >= e_s
              for i_s, e_s in zip(image_list[0].shape, example_size)
          ]
      ), "Image must be bigger than example shape"
      assert image_list[0].ndim - 1 == len(example_size) or image_list[
          0
      ].ndim == len(example_size), "Example size doesnt fit image size"
  
      for i in image_list:
          if len(image_list) > 1:
              assert (
                  i.ndim - 1 == image_list[0].ndim
                  or i.ndim == image_list[0].ndim
                  or i.ndim + 1 == image_list[0].ndim
              ), "Example size doesnt fit image size"
  
              assert all(
                  [
                      i0_s == i_s
                      for i0_s, i_s in zip(image_list[0].shape, i.shape)
                  ]
              ), "Image shapes must match"
  
      rank = len(example_size)
  
      # Extract random examples from image and label
      valid_loc_range = [
          image_list[0].shape[i] - example_size[i] for i in range(rank)
      ]
  
      rnd_loc = [
          np.random.randint(valid_loc_range[dim], size=n_examples)
          if valid_loc_range[dim] > 0
          else np.zeros(n_examples, dtype=int)
          for dim in range(rank)
      ]
  
      examples = [[]] * len(image_list)
      for i in range(n_examples):
          slicer = [
              slice(
                  rnd_loc[dim][i], rnd_loc[dim][i] + example_size[dim]
              )
              for dim in range(rank)
          ]
  
          for j in range(len(image_list)):
              ex_image = image_list[j][slicer][np.newaxis]
              # Concatenate and return the examples
              examples[j] = (
                  np.concatenate((examples[j], ex_image), axis=0)
                  if (len(examples[j]) != 0)
                  else ex_image
              )
  
      if was_singular:
          return examples[0]
      return examples
  
file_path: DLTK/dltk/io/augmentation.py
imports: from __future__ import unicode_literals
  from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from scipy.ndimage.interpolation import map_coordinates
  from scipy.ndimage.filters import gaussian_filter
label_desc: Use image node_id 6 for calling a global function with example usage: extract_random_example_array(image_list, example_size, n_examples) and returns: examples, examples