ndarraytofile
ndarray.tofile, commonly referred to as ndarraytofile, is a method of NumPy's ndarray class that writes the elements of an array to a file. It accepts a file name or a file-like object as its first argument. The second argument, sep, controls the output format: if sep is an empty string (the default), the array is written as raw binary data; if sep is non-empty, the array is written as text with values separated by sep using the specified format string (the default format is a representation suitable for Python).
The data are written in the array’s memory order. For typical C-contiguous arrays, this corresponds to row-major
Reading data written with tofile is done with numpy.fromfile, which requires the correct dtype. If the file
a = np.arange(6).reshape(2, 3)
b = np.fromfile('out.bin', dtype=a.dtype).reshape(a.shape)
b_text = np.fromfile('out.txt', sep=',', dtype=a.dtype).reshape(a.shape)
Limitations include the lack of stored shape or dtype in the file, so reading requires prior knowledge