Is there a way to dump a NumPy array into a CSV file? I have a 2D NumPy array and need to dump it in human-readable format.
Join them; it only takes a minute:
numpy.savetxt saves an array to a text file.
|
|||||||||||||||||||||
|
The man page has some useful notes:
Note. This fuction does not produce multi-line csv files, it saves everything to one line. |
|||||||||
|
savetxt may just be sufficient. |
|||||
|
If you want to save your numpy array (e.g. Then save it the normal way to one cell, with Then you could restore your array like this:
|
||||
|
Writing record arrays as CSV files with headers requires a bit more work. This example reads a CSV file with the header on the first line, then writes the same file.
Note that this example does not consider strings with commas, which would require quotes. |
|||
|
It's easy and fast with pandas
|
|||
|