python讀取二進(jìn)制mnist實例詳解
更新時間:2017年05月31日 16:04:19 投稿:lqh
這篇文章主要介紹了python讀取二進(jìn)制mnist實例詳解的相關(guān)資料,需要的朋友可以參考下
python讀取二進(jìn)制mnist實例詳解
training data 數(shù)據(jù)結(jié)構(gòu):
<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()
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
python的dict,set,list,tuple應(yīng)用詳解
這篇文章主要介紹了python的dict,set,list,tuple應(yīng)用詳解,需要的朋友可以參考下2014-07-07
Python內(nèi)建類型int源碼學(xué)習(xí)
這篇文章主要為大家介紹了Python內(nèi)建類型int源碼學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
python pandas最常用透視表實現(xiàn)應(yīng)用案例
透視表是一種可以對數(shù)據(jù)動態(tài)排布并且分類匯總的表格格式,它在數(shù)據(jù)分析中有著重要的作用和地位,在本文中,我將為你介紹python中如何使用pandas包實現(xiàn)透視表的功能,以及一些常見的應(yīng)用案例2024-01-01
Django restframework 源碼分析之認(rèn)證詳解
這篇文章主要介紹了Django-restframework 源碼分析之認(rèn)證詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-02-02
在Python中實現(xiàn)函數(shù)重載的示例代碼
這篇文章主要介紹了在Python中實現(xiàn)函數(shù)重載的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
使用python和opencv的mask實現(xiàn)摳圖疊加
這篇文章主要介紹了使用python和opencv的mask實現(xiàn)摳圖疊加操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04

