I want to write in csv file 3 columns. One with a number, one with a purpose (training/testing) and the third one with a numpy array.
I tried this code
with open('resources/new_file.csv', 'w', newline='') as csvfile:
row_writer = csv.writer(csvfile, delimiter=',')
for i, row in enumerate(data):
image = np.fromstring(row, dtype='uint8', sep=' ')
image = np.reshape(image, (48, 48))
x_train[i] = image
img = image
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face_cascade.detectMultiScale(img, 1.1, 2)
for (x, y, w, h) in faces:
new_img = cv2.resize(img[y: y + h, x:x + w], dsize=(48, 48), interpolation=cv2.INTER_CUBIC)
image_str = new_img.flatten()
row_writer.writerow([emotion[i], purpose[i], image_str])
csvfile.close()
but after opening the csv file every row is like that (exactly like that with the ...)
3,Training,[ 49 72 85 ... 192 188 185]
Also notice that between some numbers, there is a double space.
How can i write the whole thing to be like
3,Training,49 72 85 12 0 [here every other number from array] 192 188 185
image_str = new_img.flatten(), please addprint(image_str); what does that give you?' '.join(map(str,image_str))?image_stris anumpy.ndarray, and then you simply write the string representation of the array