【发布时间】:2022-11-04 17:53:42
【问题描述】:
我有这个 10,000 行的数据集,我正在尝试将卷积核应用于每一行,但我的代码只产生最后一行。
test_data_file = open("mnist_test.csv", 'r')
test_data_list = test_data_file.readlines()
test_data_file.close()
for record in test_data_list: # test_data_list is all the values in the test file
all_values = record.split(',') # split each record (image) into values seperated by commas
correct_label = int(all_values[0]) # the first value is the lab
inputs = (numpy.asfarray(all_values[1:]))
original = numpy.asfarray(inputs.reshape((28,28))) # the list is made into an array
sharpen_kernel = np.array([
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]])
matplotlib.rcParams['figure.figsize'] = 20,20 # convolve your image with the kernel
conv_image = numpy.ones((28,28))
# make a subarray and convolve it with the kernel
step = 3
i=0
while i < 25:
i+=1
j = 0
while j < 25 :
sub_image = original[i:(i+step),j:(j+step):]
sub_image = numpy.reshape(sub_image,(1,(step ** 2)))
kernel = numpy.reshape(sharpen_kernel, ((step ** 2),1))
conv_scalar = numpy.dot(sub_image,kernel)
sharpened[i,j] = conv_scalar
j+=1
pass
如何使其产生将新值写入新文件的输出?
【问题讨论】:
-
你应该开始使用 pandas 库 (pandas.pydata.org)
-
你想写什么输出?
-
卷积后具有新值的新 csv 文件。原始 csv 文件包含 10000 个 mnist 测试数据。
-
这些值在您的代码中的什么位置?
标签: python csv convolution