Saving data with numpy vstack
Say we have a numpy array we want to save to a file
It will give a file with the following content
0.0e+00 8.0e+00 7.0e+00 6.0e+00 1.0e+01 7.0e+00 9.0e+00 9.0e+00 0.0e+00 3.0e+00
This is great, the column based representation means that its easy to import into csv compatible programs like excel, LabView, Matlab and Origin.
But what happens when we want to save two or more arrays together and make sure the file is still easily importable into different programs.
If we just use
9.0e+00 9.0e+00 4.0e+00 2.0e+00 0.0e+00 8.0e+00 1.0e+01 2.0e+00 1.0e+00 9.0e+00 2.0e+00 3.0e+00 1.0e+00 9.0e+00 2.0e+00 5.0e+00 1.0e+01 2.0e+00 8.0e+00 3.0e+00 9.0e+00 8.0e+00 2.0e+00 7.0e+00 9.0e+00 0.0e+00 6.0e+00 0.0e+00 2.0e+00 3.0e+00
So instead lets use numpy vstack.
This gives us a
9.0e+00 2.0e+00 9.0e+00 9.0e+00 3.0e+00 8.0e+00 4.0e+00 1.0e+00 2.0e+00 2.0e+00 9.0e+00 7.0e+00 0.0e+00 2.0e+00 9.0e+00 8.0e+00 5.0e+00 0.0e+00 1.0e+01 1.0e+01 6.0e+00 2.0e+00 2.0e+00 0.0e+00 1.0e+00 8.0e+00 2.0e+00 9.0e+00 3.0e+00 3.0e+00
Which is much more portable, and can be imported into programs like excel easily.
To read the file again using numpy into the arrays use
This is a quick and easy way to get arrays in and out of files from numpy. It keeps the files portable for use with other programs.