code: def read_mnist(dataset, path):
      if dataset is "training":
          fname_img = os.path.join(path, "train-images-idx3-ubyte")
          fname_lbl = os.path.join(path, "train-labels-idx1-ubyte")
      elif dataset is "testing":
          fname_img = os.path.join(path, "t10k-images-idx3-ubyte")
          fname_lbl = os.path.join(path, "t10k-labels-idx1-ubyte")
      else:
          raise ValueError("dataset must be 'testing' or 'training'")
  
      # Load everything in some numpy arrays
      with open(fname_lbl, "rb") as flbl:
          magic, num = struct.unpack(">II", flbl.read(8))
          labels = np.fromfile(flbl, dtype=np.int8)
  
      with open(fname_img, "rb") as fimg:
          magic, num, rows, cols = struct.unpack(">IIII", fimg.read(16))
          images = np.multiply(
              np.fromfile(fimg, dtype=np.uint8).reshape(
                  len(labels), rows * cols
              ),
              1.0 / 255.0,
          )
  
      get_instance = lambda idx: (labels[idx], images[idx])
  
      # Create an iterator which returns each image in turn
      for i in range(len(labels)):
          yield get_instance(i)
  
file_path: dynet/examples/mnist/mnist-autobatch.py
imports: import time
  import random
  import os
  import struct
  import argparse
  import numpy
  import dynet
label_desc: Use image node_id 1 for calling a global function with example usage: read_mnist(dataset, path) without return types