python - csv文件被覆盖而不是附加在python中
问题描述
Python 中的问题 - 只有最后一个 numpy 数组被写入 .csv 文件,而不是所有数组都被附加到它。我该如何解决这个问题?
import cv2, glob
from PIL import Image
import numpy as np
images = glob.glob('*.bmp')
for image in images:
img=cv2.imread(image,0) #original image
re=cv2.resize(img, dsize=(128,128), interpolation=cv2.INTER_LINEAR)
cv2.imwrite("resized_"+image,re) #resized image
a = np.asarray(re) #resized image is converted to pixels
np.savetxt("sal.csv",a, delimiter=',')
print(np.asarray(re)) #which are printed to csv file. Problem is only the last image pixel values are printed to csv file. Any suggestions to rectify this.
解决方案
推荐阅读
- azure - 雪花连接器 .Net 连接测试失败 用户名和密码不正确
- python - python缩进命名空间
- javascript - 如何防止 Canvas 的笔画像素在放大时保持清晰?
- pyserial - Pyserial + 不带终止字符的定长消息协议
- php - 令牌如何防止服务器端的多个表单提交?
- wordpress - 为什么一个函数在 mamp 而不是在主机服务器上工作?
- python - 使用递归将列表中的列表转换为仅包含整数的列表
- java - 如何将两个文件的特定列复制到Java中的一个文件中?
- machine-learning - 即使在对数据集进行过采样之后,性能也非常低
- delay - 延迟 10 秒正在增加 arduino