code: def read(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 'training' or 'testing'")
  
      with open(fname_lbl, "rb") as flbl:
          _, _ = struct.unpack(">II", flbl.read(8))
          lbl = np.fromfile(flbl, dtype=np.int8)
  
      with open(fname_img, "rb") as fimg:
          _, _, rows, cols = struct.unpack(">IIII", fimg.read(16))
          img = np.multiply(
              np.fromfile(fimg, dtype=np.uint8).reshape(
                  len(lbl), rows, cols
              ),
              1.0 / 255.0,
          )
  
      get_img = lambda idx: (lbl[idx], img[idx])
  
      for i in range(len(lbl)):
          yield get_img(i)
  
file_path: dynet/examples/mnist/basic-mnist-benchmarks/mnist_dynet_minibatch.py
imports: from __future__ import division
  import os
  import struct
  import argparse
  import random
  import time
  import numpy
  import dynet
label_desc: Use image node_id 1 for calling a global function with example usage: read(dataset, path) without return types