首页 > 解决方案 > 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.

标签: pythonarrayscsvnumpy

解决方案


推荐阅读