导库
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
读取mnist数据
import numpy as np
path='./mnist.npz'
f = np.load(path)
train_x, train_y = f['x_train'], f['y_train'] # 训练集
test_x, test_y = f['x_test'], f['y_test'] # 测试集
f.close()
查看数据格式
print(train_x.shape)
print(train_y.shape)
print(test_x.shape)
print(test_y.shape)
将数据以图片形式输出
plt.imshow(train_x[10000])
将数据格式改为DNN可接收的一维格式
train_x = train_x.reshape((60000,28*28),order='C') # 将二维的图片展开为一维的数据(训练集)
test_x = test_x.reshape((10000,28*28),order='C')