def load_mnist(data_dir=None):
    if data_dir is None:
        import urllib
        import gzip
        url = 'http://yann.lecun.com/exdb/mnist/'
        fnames = [
            'train-images-idx3-ubyte.gz', 
            'train-labels-idx1-ubyte.gz', 
            't10k-images-idx3-ubyte.gz', 
            't10k-labels-idx1-ubyte.gz'
        ]
        for fname in fnames:
            if not os.path.isfile(fname):
                print 'data_dir not given and file not local - downloading mnist file:', fname
                urllib.urlretrieve(url+fname, fname)
        data_dir = ''
    fd = gzip.open(os.path.join(data_dir,'train-images-idx3-ubyte.gz'))
    loaded = np.fromstring(fd.read(), dtype=np.uint8)
    trX = loaded[16:].reshape((60000, -1))

    fd = gzip.open(os.path.join(data_dir,'train-labels-idx1-ubyte.gz'))
    loaded = np.fromstring(fd.read(), dtype=np.uint8)
    trY = loaded[8:].reshape((60000))

    fd = gzip.open(os.path.join(data_dir,'t10k-images-idx3-ubyte.gz'))
    loaded = np.fromstring(fd.read(), dtype=np.uint8)
    teX = loaded[16:].reshape((10000, -1))

    fd = gzip.open(os.path.join(data_dir,'t10k-labels-idx1-ubyte.gz'))
    loaded = np.fromstring(fd.read(), dtype=np.uint8)
    teY = loaded[8:].reshape((10000))

    trX = trX/255.
    teX = teX/255.

    trX = trX.reshape(-1, 28, 28)
    teX = teX.reshape(-1, 28, 28)
    
    return trX, teX, trY, teY
dataset/ETHPy150Open IndicoDataSolutions/Passage/examples/load.py/load_mnist/original