code: def download_and_parse_mnist_file(
      file_name, datadir=None, force=False
  ):
      url = os.path.join(
          "https://storage.googleapis.com/cvdf-datasets/mnist/",
          file_name,
      )
      file_name = maybe_download_file(url, datadir=datadir, force=force)
  
      # Open the file and unzip it if necessary
      if os.path.splitext(file_name)[1] == ".gz":
          open_fn = gzip.open
      else:
          open_fn = open
  
      # Parse the file
      with open_fn(file_name, "rb") as file_descriptor:
          header = file_descriptor.read(4)
          assert len(header) == 4
  
          zeros, data_type, n_dims = struct.unpack(">HBB", header)
          assert zeros == 0
  
          hex_to_data_type = {
              0x08: "B",
              0x09: "b",
              0x0B: "h",
              0x0C: "i",
              0x0D: "f",
              0x0E: "d",
          }
          data_type = hex_to_data_type[data_type]
  
          # data_type unicode to ascii conversion (Python2 fix)
          if sys.version_info[0] < 3:
              data_type = data_type.encode("ascii", "ignore")
  
          dim_sizes = struct.unpack(
              ">" + "I" * n_dims, file_descriptor.read(4 * n_dims)
          )
  
          data = array.array(data_type, file_descriptor.read())
          data.byteswap()
  
          desired_items = functools.reduce(operator.mul, dim_sizes)
          assert len(data) == desired_items
          return np.array(data).reshape(dim_sizes)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import array
  import functools
  import gzip
  import operator
  import os
  import struct
  import tempfile
  import sys
  import warnings
  import numpy
  import tensorflow
  from cleverhans import utils
label_desc: Use image node_id 2 for calling a global function with example usage: download_and_parse_mnist_file(file_name, datadir, force) and returns: np