Jupyter notebook显示MNIST图片

用Jupyter notebook,显示MNIST

 

 1 %matplotlib inline
 2 
 3 from keras.datasets import mnist
 4 import matplotlib.pyplot as plt
 5 
 6 # loading data
 7 (X_train, y_train), (X_test, y_test) = mnist.load_data()
 8 
 9 fig = plt.figure()
10 ax = fig.add_subplot(221)   #第一个子图
11 
12 ax.imshow(X_train[0])   #默认配置
13 
14 ax = fig.add_subplot(222)   #第二个子图
15 
16 ax.imshow(X_train[1])    
17 
18 ax = fig.add_subplot(223)   #第三个子图
19 
20 ax.imshow(X_train[2],cmap = plt.cm.gray)   #第三个子图,使用灰度图
21 
22 ax = fig.add_subplot(224)   #第四个子图
23 
24 ax.imshow(X_train[3],cmap = plt.cm.gray)   #第四个子图,使用灰度图
25 
26 plt.show()   #显示图像

 

结果:

 

转载于:https://www.cnblogs.com/zmm1996/p/10715268.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值