讀取mnist資料集顯示圖片資訊
阿新 • • 發佈:2018-12-12
MNIST資料集下載地址https://download.csdn.net/download/weixin_33595571/10826617
QQ群:476842922(歡迎加群討論學習)
import numpy as np
import struct
import matplotlib.pyplot as plt
filename = 'train-images.idx3-ubyte'
binfile = open(filename , 'rb')
buf = binfile.read()
index = 1
magic, numImages , numRows , numColumns = struct.unpack_from('>IIII' , buf , index)
index += struct.calcsize('>IIII')
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()