python - How to print a list of arrays transposed in a csv file -


i have list contains arrays (type = numpy.ndarray) in following form:

final = [[a, b, c, d],[e, f, g, h],[i, j, k, l]] 

and print them transposed in csv file in following form:

a, e, b, f, j c, g, k d, h, l 

where a,b,c...j, k, l strings (numpy.string_). tried approach list containing lists (which answered in post) not work, instead in creates empty csv file. attempt one:

csvfile=open('new.csv','wb')     wr = csv.writer(csvfile) final=map(list, zip(*final)) wr.writerows(final) csvfile.close() 

can offer advice?

you can convert list numpy array: final = np.array(final) , use transpose method numpy.ndarray.t way:

final.t = [[a, e, i],[b, f, j],[c, g, k],[d,h,l]]

so:

import numpy np np.savetxt("foo.csv", np.array(final).t, delimiter=",") 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -