numpy File IO with numpy Saving data as CSV style ASCII file


Example

Analog to np.loadtxt, np.savetxt can be used to save data in an ASCII file

import numpy as np
x = np.random.random([100,100])
np.savetxt("filename.txt", x)

To control formatting:

np.savetxt("filename.txt", x, delimiter=", " , 
    newline="\n", comments="$ ", fmt="%1.2f",
    header="commented example text")

Output:

$ commented example text
0.30, 0.61, 0.34, 0.13, 0.52, 0.62, 0.35, 0.87, 0.48, [...]