Saving a Compressed File with numpy

This page gives an example of saving a compressed file using numpy. As with any file format, a programmer should feel comfortable reading and writing files. The reason for compressing files is that the file sizes in machine learning applications can be enormous. Anything you can do to reduce the payload can result in more efficient file processing.

Example: Save data as a .npz file

# save numpy array as npy file
from numpy import asarray
from numpy import save
# define data
data = asarray([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
# save to npy file
save('data.npy', data)

# load numpy array from npy file
from numpy import load
# load array
data = load('data.npy')
# print the array
print(data)

Source: newbedev, https://newbedev.com/python-npz-numpy-save-code-example
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.

Last modified: Monday, October 3, 2022, 11:58 AM