【发布时间】:2018-02-26 01:26:36
【问题描述】:
在 MNIST 数据集中,我有 CSV 格式的图像,784 列中的每一列对应一个像素强度。我想保存这些图像中的每一个而不用imshow查看它们。
import numpy as np
import csv
import matplotlib.pyplot as plt
i=0
with open('Book1.csv', 'r') as csv_file:
for data in csv.reader(csv_file):
# The rest of columns are pixels
pixels = data[:]
# This array will be of 1D with length 784
# The pixel intensity values are integers from 0 to 255
pixels = np.array(pixels, dtype='uint8')
# Reshape the array into 28 x 28 array (2-dimensional array)
pixels = pixels.reshape((28, 28))
i +=1
# Plot
plt.title('Label is {label}'.format(label=label))
plt.imshow(pixels, cmap='gray')
plt.savefig(str(i))'
这样我无法保存每张图片。
【问题讨论】:
-
你能说得更具体点吗?运行脚本时究竟会发生什么?最后一行末尾的撇号是故意的吗?
标签: python csv matplotlib mnist