如何编辑 mnist 数据集?

How to edit mnist dataset?

我想在“mnist 数据集”中包含数字 0 到 5。 我如何在 python 上执行此操作? 我尝试用 numpy.delete 解决这个问题,但没有成功。

假设您将图像存储在形状为 (num_examples, num_pixels) 的 numpy 数组中,并将标签存储在形状为 (num_examples,) 的数组中,您可以这样做:

images = images[labels <= 5].copy()
labels = labels[labels <= 5].copy()

尝试获取与范围 (6) 中的标签关联的图像。所以,你可以写一个类似于下面的函数:

images_5 = []
label_5 = []
for img, label in zip(images, labels):
    if label in range(6):
        images_5.append(img)
        labels_5.append(label)

不确定是否可行,但我认为应该可行!