I converted images to numpy array and saved to csv file
back_ground = Back_ground()
X = make_test_set('back_ground.csv',back_ground,3500)
Y = back_ground.make_answer()
with open('background.csv','w',newline='') as csvfile:
fieldnames = ['image','answer']
writer = csv.DictWriter(csvfile,fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'image': X, 'answer':Y})
make_test_set() and make_answer() return numpy.ndarray
But when I want to use this data, like this
with open('background.csv','r') as csvfile:
reader = csv.DictReader(csvfile)
for number,value in enumerate(reader):
print(number)
current_img = value['image']
print(type(current_img))
plt.imshow(current_img)
plt.show()
type of currnet_img is string so I can't use any numpy functions
how can I convert to numpy.ndarray? or are there any good method to save numpy.ndarray?
XandY? What does the resultingcsvfile look like? Thecsvformat is just numbers (or strings) separated by delimiters. The arenumpyfunctions for writing and readingcsv-np.savetxtandnp.loadtxt. But they work best with simple 2d numeric arrays. There also binary save methods likenp.saveandnp.load.