简体   繁体   中英

Write multiple NumPy arrays into CSV file in separate columns?

How to write multiple numpy arrays into one csv file in multiple columns?

import numpy
import csv

arrA = numpy.array(file.root.a)
arrB = numpy.array(file.root.b)
arrC = numpy.array(file.root.c)

for i in range (480):
    for j in range (640):
        (write arrA[i,j] into column1,write arrB[i,j] into column2,write arrC[i,j] into column3)

Thanks a lot!

I think this should do what you want:

output = np.column_stack((arrA.flatten(),arrB.flatten(),arrC.flatten()))
np.savetxt('output.dat',output,delimiter=',')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM