【发布时间】:2020-09-05 08:20:54
【问题描述】:
我想向 csv 文件添加 1 个标题,但标题将添加到每一行。 this is what i got
IMG_DIR = 'path to the images'
for img in os.listdir(IMG_DIR):
img_array = cv2.imread(os.path.join(IMG_DIR,img), cv2.IMREAD_COLOR)
img_array = (img_array.flatten())
img_array = img_array.reshape(-1, 1).T
print(img_array)
with open('Data.csv', 'ab') as c:
np.savetxt(c, img_array , fmt='%d', delimiter=",", header=',', comments='')
【问题讨论】:
-
savetxt每次调用它时都会做同样的事情。文件已经退出的事实并没有改变这一点。