https://github.com/daniel-e/mnistdb
Load MNIST handwritten digits with Python
https://github.com/daniel-e/mnistdb
machine-learning mnist python
Last synced: 7 days ago
JSON representation
Load MNIST handwritten digits with Python
- Host: GitHub
- URL: https://github.com/daniel-e/mnistdb
- Owner: daniel-e
- License: mit
- Created: 2017-10-31T19:55:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-07T12:50:24.000Z (over 8 years ago)
- Last Synced: 2025-12-16T17:40:01.647Z (6 months ago)
- Topics: machine-learning, mnist, python
- Language: Python
- Size: 13.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# mnistdb
mnistdb is a library which loads the
[MNIST database of handwritten digits](http://yann.lecun.com/exdb/mnist/)
into numpy arrays.
## Install
pip install mnistdb
## Running
```Python
import mnistdb.io as mio
data = mio.load()
# shape of data
assert x.trainX.shape == (60000, 784)
assert x.trainY.shape == (60000,)
assert x.testX.shape == (10000, 784)
assert x.testY.shape == (10000,)
# With the parameter scaled=True all pixel values are
# scaled into the interval [0,1]
data = mio.load(scaled=True)
```
When you're running the code for the first time mnistdb will download
the MNIST database of handwritten digits from the Internet. The database
will be stored in `~/.mnistdb` so that does not need to download the
database for subsequent calls.
If you want one-hot encoded labels call `load` with the parameter
`one_hot=True`.
```Python
import mnistdb.io as mio
n = mio.load()
o = mio.load(one_hot=True)
# print the labels of the first five training examples
print(n.trainY[range(5)])
# print the one-hot encoded labels of the first five training examples
print(o.trainY[range(5), :])
```
The output is:
```
[5 0 4 1 9]
[[ 0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]
[ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]
[ 0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]]
```