python读取二进制mnist实例详解
2017-05-31 16:04
846 查看
python读取二进制mnist实例详解
training data 数据结构:
<br>[offset] [type] [value] [description] 0000 32 bit integer 0x00000803(2051) magic number 0004 32 bit integer 60000 number of images 0008 32 bit integer 28 number of rows 0012 32 bit integer 28 number of columns 0016 unsigned byte ?? pixel 0017 unsigned byte ?? pixel ........ xxxx unsigned byte ?? pixel
将整个文件读入:
filename = 'train-images.idx3-ubyte' binfile = open(filename , 'rb') buf = binfile.read()
读取头四个32bit的interger:
index = 0 magic, numImages , numRows , numColumns = struct.unpack_from('>IIII' , buf , index) index += struct.calcsize('>IIII')
读取一个图片,784=28*28 :
im = struct.unpack_from('>784B' ,buf, index) index += struct.calcsize('>784B') im = np.array(im) im = im.reshape(28,28) fig = plt.figure() plotwindow = fig.add_subplot(111) plt.imshow(im , cmap='gray') plt.show()
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- python下读取公私钥做加解密实例详解
- python读取Excel实例详解
- 详解python实现读取邮件数据并下载附件的实例
- 使用python读取tensorflow实例中的MNIST模拟数据
- 利用Java读取二进制文件实例详解
- python 读取excel文件生成sql文件实例详解
- Python使用struct处理二进制的实例详解
- 【python】详解zipfile模块读取处理压缩文件实例
- python进制转换(读取纯二进制文件内容)
- 详解vb.net实现图片以二进制形式上传和读取到数据库
- 详解vb.net实现图片以二进制形式上传和读取到数据库
- FileReader详解与实例---读取并显示图像文件
- Python中的 new-style class 及其实例详解
- Python 二进制文件读取显示 (转)
- 【原】Python 用例:二进制写入和读取文件内容
- 详解python2 和 python3的区别[附实例]
- FileReader详解与实例---读取并显示图像文件
- FileReader详解与实例---读取并显示图像文件 | JS Mix
- python读取mnist
- 详解vb.net实现图片以二进制形式上传和读取到数据库