Save numpy based array in different lines of excel file

I have code that generates numpy.array in every loop. I want to save the array as a string in an excel file (i.e., the array created in the first loop will become the first row, the array generated in the second loop will become the second row, etc.). An array is created as follows:

for a loop in range(0,10) :

 Array1 = ..... Array2 = ...... Array3 = numpy.concatenate((Array1,Array2),axis=0) 

Any idea how I can put Array3 in 10 different lines of an excel file? (If the array is 5-dimensional, the excel file should contain 10 rows and 5 columns).

+4
source share
2 answers

Assuming data is a list of your arrays and make sure all your arrays are the same size, you can use np.savetxt to save your data in a TSV / CSV file, as suggested by @Qnan

 np.savetxt(your_output_file, np.array(data), delimiter="\t") 

See the np.savetxt documentation for more information on how to format fields, if necessary.

The idea is to write the file right away, not line by line.

+6
source

Export to TSV or CSV file (tab / comma), Excel can open them.

Basically, if you print the values ​​in a simple text file line by line and separate them on the same line with a tab character ( '\t' ), Excel will be able to read this file. You may need to call it .xls .

-1
source

All Articles