NumPy's native .npy format stores a single array efficiently. np.save/np.load and np.savez for multiple named arrays in one archive.
Single array
import numpy as np
a = np.array([1, 2, 3])
# np.save('data.npy', a)
# b = np.load('data.npy')
print('Use save/load in local projects')
Multiple arrays
np.savez('archive.npz', X=X, y=y) bundles arrays. Load with data = np.load('archive.npz'); data['X'].
Playground cannot write files—practice locally with notebooks.
Alternatives
- CSV — human-readable, slow, lossy for floats
- Parquet — via Pandas/pyarrow for tables
- HDF5 — large scientific datasets
Important interview questions and answers
- Q: Why .npy over pickle?
A: Npy is array-specific, faster, safer—no arbitrary code execution on load. - Q: savez_compressed?
A: Adds zlib compression—smaller disk at CPU cost.
Self-check
- Which function loads a .npy file?
- How do you save two arrays X and y in one file?
Tip: Practice np.save/np.load locally—playground has no disk writes.
Interview prep
- npy vs pickle?
Npy is array-specific, faster, safer—no arbitrary code execution.
- savez?
Multiple named arrays in one .npz archive.