code: def read_mnist_images(filename, dtype=None):
      
      with gzip.open(filename, 'rb') as f:
          magic, number, rows, cols = struct.unpack('>iiii', f.read(16))
          if magic != MNIST_IMAGE_MAGIC:
              raise ValueError("Wrong magic number reading MNIST image file")
          array = numpy.frombuffer(f.read(), dtype='uint8')
          array = array.reshape((number, 1, rows, cols))
      if dtype:
          dtype = numpy.dtype(dtype)
  
          if dtype.kind == 'b':
              # If the user wants Booleans, threshold at half the range.
              array = array >= 128
          elif dtype.kind == 'f':
              # Otherwise, just convert.
              array = array.astype(dtype)
              array /= 255.
          else:
              raise ValueError("Unknown dtype to convert MNIST to")
      return array
docs: Read MNIST images from the original ubyte file format.
  
      Parameters
      ----------
      filename : str
          Filename/path from which to read images.
  
      dtype : 'float32', 'float64', or 'bool'
          If unspecified, images will be returned in their original
          unsigned byte format.
  
      Returns
      -------
      images : :class:`~numpy.ndarray`, shape (n_images, 1, n_rows, n_cols)
          An image array, with individual examples indexed along the
          first axis and the image dimensions along the second and
          third axis.
  
      Notes
      -----
      If the dtype provided was Boolean, the resulting array will
      be Boolean with `True` if the corresponding pixel had a value
      greater than or equal to 128, `False` otherwise.
  
      If the dtype provided was a float dtype, the values will be mapped to
      the unit interval [0, 1], with pixel values that were 255 in the
      original unsigned byte representation equal to 1.0.