下载 地址:http://yann.lecun.com/exdb/mnist/
解压 如图
上传 使用的是Jupyter Notebook,所以有这一步,其他编辑器自己考虑路径
代码
import os
import struct
import numpy as np
def read_mnist(labels_path,images_path):
with open(labels_path, 'rb') as lbpath:
magic, n = struct.unpack('>II',
lbpath.read(8))
labels = np.fromfile(lbpath,
dtype=np.uint8)
with open(images_path, 'rb') as imgpath:
magic, num, rows, cols = struct.unpack('>IIII',