码迷,mamicode.com
首页 > 数据库 > 详细

python读取mnist label数据库

时间:2017-05-31 22:12:38      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:xxx   number   read   unsigned   port   sig   xxxx   unp   download   

<br>[offset] [type]          [value]          [description]
0000     32 bit integer  0x00000803(2051) magic number
0004     32 bit integer  60000            number of items

0008     unsigned byte   ??               label
0009     unsigned byte   ??               label
........
xxxx     unsigned byte   ??               label

 Mnist label数据结构如上.

完整代码:

import struct

filename = ‘/home/xxxx/Downloads/train-labels.idx1-ubyte‘
binFile = open(filename, ‘rb‘)
buf = binFile.read()

index = 0
magic, train_label_num = struct.unpack_from(‘>II‘, buf, index)
print(magic)
print(train_label_num)

index += struct.calcsize(‘>II‘)

train_label_lis=[]

for i in range(train_label_num):
    label_item = int(struct.unpack_from(‘>B‘, buf, index)[0])
    train_label_lis.append(label_item)
    index += struct.calcsize(‘B‘)


print(train_label_lis[0])

 

python读取mnist label数据库

标签:xxx   number   read   unsigned   port   sig   xxxx   unp   download   

原文地址:http://www.cnblogs.com/hit-wangjun/p/6925979.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!