python讀取二進制mnist實例詳解
更新時間:2017年05月31日 16:04:19 投稿:lqh
這篇文章主要介紹了python讀取二進制mnist實例詳解的相關(guān)資料,需要的朋友可以參考下
python讀取二進制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 Stanza處理NLP任務(wù)使用詳解(多語言處理工具)
這篇文章主要為大家介紹了python Stanza處理NLP任務(wù)使用詳解,多語言處理工具使用實例探索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-01-01Python?實現(xiàn)多表和工作簿合并及一表按列拆分
這篇文章主要介紹了Python?實現(xiàn)多表和工作簿合并及一表按列拆分,文章圍繞主題展開詳細的資料介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-05-05Windows系統(tǒng)下安裝tensorflow的配置步驟
這篇文章主要介紹了Windows系統(tǒng)下安裝tensorflow,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07