code: def extract_images(f):
      """Extract the images into a 4D uint8 numpy array [index, y, x, depth].
  
      :param: f: A file object that can be passed into a gzip reader.
      :return: data: A 4D unit8 numpy array [index, y, x, depth].
      :raise: ValueError: If the bytestream does not start with 2051.
  
      """
      print("Extracting", f.name)
      with gzip.GzipFile(fileobj=f) as bytestream:
          magic = _read32(bytestream)
          if magic != 2051:
              invalidInputError(
                  False,
                  "Invalid magic number %d in MNIST image file: %s"
                  % (magic, f.name),
              )
          num_images = _read32(bytestream)
          rows = _read32(bytestream)
          cols = _read32(bytestream)
          buf = bytestream.read(rows * cols * num_images)
          data = numpy.frombuffer(buf, dtype=numpy.uint8)
          data = data.reshape(num_images, rows, cols, 1)
          return data
  
file_path: BigDL/python/dllib/src/bigdl/dllib/keras/datasets/mnist.py
imports: import gzip
  import numpy
  from bigdl.dllib.feature.dataset import base
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 2 for calling a global function with example usage: extract_images(f) and returns: data