python怎么导入mnist数据集

1689
2024/1/4 16:17:33
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

您可以使用以下代码导入MNIST数据集:

from tensorflow.keras.datasets import mnist

# 加载MNIST数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()

# 输出训练集和测试集的形状
print('训练集:', x_train.shape, y_train.shape)
print('测试集:', x_test.shape, y_test.shape)

这段代码使用了TensorFlow的keras.datasets模块中的mnist函数来加载MNIST数据集。加载后,数据集被拆分为训练集和测试集,分别存储在(x_train, y_train)(x_test, y_test)变量中。此外,代码还输出了训练集和测试集的形状。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: 如何用fillna函数处理特定类型的缺失值