python显示MNIST图像和标签

import tensorflow as tf  
import numpy as np
import matplotlib.pyplot as plt

mnist = tf.keras.datasets.mnist  
(x_train, y_train), (x_test, y_test) = mnist.load_data()

img = x_train[0]
label = y_train[0]
print(label)
print(img.shape)


def img_show(image):
...     plt.imshow(image)
...     plt.axis('off')  # Hide axes
...     plt.show()

img_show(img)
展开/折叠结果
>>> print(label)
5
>>> print(img.shape)
(28, 28)

评论

发表评论

了解 数据控|突破是我们的每一步 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读