code: def preprocess_mnist(
      raw, withlabel, ndim, scale, image_dtype, label_dtype, rgb_format
  ):
      images = raw["x"]
      if ndim == 2:
          images = images.reshape(-1, 28, 28)
      elif ndim == 3:
          images = images.reshape(-1, 1, 28, 28)
          if rgb_format:
              images = numpy.broadcast_to(
                  images, (len(images), 3) + images.shape[2:]
              )
      elif ndim != 1:
          raise ValueError("invalid ndim for MNIST dataset")
      images = images.astype(image_dtype)
      images *= scale / 255.0
  
      if withlabel:
          labels = raw["y"].astype(label_dtype)
          return tuple_dataset.TupleDataset(images, labels)
      else:
          return images
  
file_path: chainer/chainer/datasets/_mnist_helper.py
imports: import gzip
  import struct
  import numpy
  import six
  from chainer.dataset import download
  from chainer.datasets import tuple_dataset
label_desc: Use image node_id 2 for calling a global function with example usage: preprocess_mnist(raw, withlabel, ndim, scale, image_dtype, label_dtype, rgb_format) and returns: tuple_dataset, images