[Numpy-discussion] how to save a large array into a file quickly

Eric Firing efiring@hawaii....
Tue Oct 14 20:29:32 CDT 2008

frank wang wrote:
> Hi,
> I have a large ndarray that I want to dump to a file. I know that I can 
> use a for loop to write one data at a time. Since Python is a very 
> powerfully language, I want to find a way that will dump the data fast 
> and clean. The data can be in floating point or integer.

Use numpy.save for a single array, or numpy.savez for multiple ndarrays, 
assuming you will want to read them back with numpy.  If you want to 
dump to a text file, use numpy.savetxt.  If you want to dump to a binary 
file to be read by another program, you might want to use the tofile 
method of the ndarray.


More information about the Numpy-discussion mailing list