Skip to main content

Simple MNIST and EMNIST data parser written in pure Python

Project description

Simple MNIST and EMNIST data parser written in pure Python.

MNIST is a database of handwritten digits available on EMNIST is an extended MNIST database


  • Python 2 or Python 3


  • git clone

  • cd python-mnist

  • Get MNIST data:

  • Check preview with:

    PYTHONPATH=. ./bin/mnist_preview


Get the package from PyPi:

pip install python-mnist

or install with

python install

Code sample:

from mnist import MNIST
mndata = MNIST('./dir_with_mnist_data_files')
images, labels = mndata.load_training()

To enable loading of gzip-ed files use:

mndata.gz = True


  • Get EMNIST data:

  • Check preview with:

    PYTHONPATH=. ./bin/emnist_preview

To use EMNIST datasets you need to call:


Where digits is one of the available EMNIST datasets. You can choose from

  • balanced
  • byclass
  • bymerge
  • digits
  • letters
  • mnist

EMNIST loader uses gziped files by default, this can be disabled by by setting:

mndata.gz = False

You also need to unpack EMNIST files as script won’t do it for you. EMNIST loader also needs to mirror and rotate images so it is a bit slower (If this is an issue for you, you should repack the data to avoid mirroring and rotation on each load).


This package doesn’t use numpy by design as when I’ve tried to find a working implementation all of them were based on some archaic version of numpy and none of them worked. This loads data files with struct.unpack instead.

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
python-mnist-0.5.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None Jan 9, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page