加载训练MNIST数据集 #加载数据集(输入代码): #查看训练数据集结构(输入代码): 输入结果: x_train.shape: y_train.shape: x_test.shape: y_test.shape:
时间: 2024-02-10 11:11:44 浏览: 82
MNIST训练数据集
以下是加载MNIST数据集和查看数据集结构的代码:
```python
import tensorflow as tf
# 加载MNIST数据集
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
# 输出训练集和测试集的形状
print("x_train.shape:", x_train.shape)
print("y_train.shape:", y_train.shape)
print("x_test.shape:", x_test.shape)
print("y_test.shape:", y_test.shape)
```
运行结果:
```
x_train.shape: (60000, 28, 28)
y_train.shape: (60000,)
x_test.shape: (10000, 28, 28)
y_test.shape: (10000,)
```
说明训练集包含60000个28x28的图像,测试集包含10000个28x28的图像。标签是长度为60000和10000的一维数组。
阅读全文