
Storing a single array in binary format
NumPy defines a binary format called NPY to store arrays. Users do not need to know the details of the format, but those interested can find its specification at the following site: https://docs.scipy.org/doc/numpy/neps/npy-format.html.
The NPY format is designed with the efficient storage of NumPy arrays in mind, including optimizations for large arrays. It is a format specific to NumPy, so it is not a suitable exchange format for a web application, for example. It is designed for personal use, or for sharing data among coworkers in the same project. It does not offer any built-in security features and should not be used to share sensitive data. NumPy also defines the NPZ file format, which is simply a ZIP file packaging several NPY files.
To store a single array in binary NPY format, we use the save() function as follows:
x = np.random.rand(200, 300)
np.save('array_x.npy', x)
The preceding code will generate an array x with random data, and then call save() to create the array_x.npy file on the disk, containing a binary representation of the array x.