MNIST数据集是一个手写体数据集
MNIST数据集里一共有70000个样例,这70000个样例又会被分为50000个Train样例,10000个Validate样例,10000个Test样例。
with gzip.open(filepath) as fp:
(x_train, y_train), (x_valid, y_valid), (x_test, y_test) = pickle.load(fp, encoding='latin1') # 在python3上面encoding是必须改成latin1,而Python2上面则不需要(可能有误)
x_all = np.vstack((x_train, x_valid, x_test))
y_all = np.hstack((y_train, y_valid, y_test))
# 这里也可以用np.concatenate(),指定axis=0即可
# x_all和y_all的type为ndarray,shape分别为(70000,784)和(70000,)
x_reshaped = x_all.reshape(shape=(x_all.shape[0],28,28,1)) # 1是channel
# 或者直接x_all.resize(shape=(x_all.shape[0],28,28,1))