给我一段python代码展示如何创建一份新的数据集,并通过循环累加将三份FashionMnist数据集汇总至该新的数据集中,形成一份新的数据集
时间: 2024-04-30 18:21:07 浏览: 16
以下是一个示例代码,用于创建一个新的数据集并将三个FashionMNIST数据集合并到该数据集中:
```python
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.datasets import fashion_mnist
# 加载FashionMNIST数据集
(x_train_1, y_train_1), (x_test_1, y_test_1) = fashion_mnist.load_data()
(x_train_2, y_train_2), (x_test_2, y_test_2) = fashion_mnist.load_data()
(x_train_3, y_train_3), (x_test_3, y_test_3) = fashion_mnist.load_data()
# 创建一个新的数据集并将FashionMNIST数据集合并到该数据集中
x_train = np.concatenate((x_train_1, x_train_2, x_train_3), axis=0)
y_train = np.concatenate((y_train_1, y_train_2, y_train_3), axis=0)
# 将像素值从[0, 255]缩放到[0, 1]
x_train = x_train.astype("float32") / 255.0
# 打印新数据集的形状
print("x_train shape:", x_train.shape)
print("y_train shape:", y_train.shape)
```
在这个示例代码中,我们首先加载三个FashionMNIST数据集并将它们存储在不同的变量中。然后,我们使用`np.concatenate`函数将这三个数据集合并到新的数据集中。最后,我们将像素值从[0, 255]缩放到[0, 1],并打印新数据集的形状。您可以根据需要调整此代码,以适应您自己的数据集。