【Mnist】用matplotlib查看Mnist数据集中的图片(由keras导入的数据集)
8行代码:
import numpy as np
import matplotlib.pyplot as plt
from keras.datasets import mnist
(X_train, Y_train), (Y_test, Y_test) = mnist.load_data() # 用过keras的都懂
indexs = 10 # X_train中60000张,想看哪张可以改
plt.imshow(X_train[indexs]) # 展示图片(28, 28)大小的
plt.title(str(Y_train[indexs])) # 标题是对应的标签
plt.show()
效果(jupyter notebook中):
plt.imshow()也可以展示多通道图片。