The .npy format stores an array's raw data alongside a small header describing its shape and dtype, so loading it back with np.load() reconstructs the exact same array, byte for byte, with none of the precision loss or parsing ambiguity that can come from a text-based format like CSV. It's specifically designed for fast, lossless round-tripping of NumPy arrays between Python sessions, not for interoperability with other tools or human readability.
1Understanding np.save()
The .npy format stores an array's raw data alongside a small header describing its shape and dtype, so loading it back with np.load() reconstructs the exact same array, byte for byte, with none of the precision loss or parsing ambiguity that can come from a text-based format like CSV. It's specifically designed for fast, lossless round-tripping of NumPy arrays between Python sessions, not for interoperability with other tools or human readability.
Use .npy, via save()/load(), for saving intermediate NumPy results within a Python workflow — it's faster to read/write and perfectly lossless, but reach for a text format like CSV specifically when the data needs to be read by other tools or inspected by a human.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
np.save("my_array.npy", arr)
loaded = np.load("my_array.npy")
print(loaded)2Practical Example
Here is a real-world application of np.save() showing how it is used in production NumPy code.
import numpy as np
original = np.array([1.5, 2.7, 3.14159265358979], dtype=np.float64)
np.save("precise.npy", original)
loaded = np.load("precise.npy")
print(np.array_equal(original, loaded))3Best Practices
Follow these guidelines when working with np.save():
1. Use np.save()/np.load() for fast, exact round-tripping of arrays within a Python-only workflow
2. Use a text format like CSV, via savetxt()/loadtxt(), instead when the data needs to be human-readable or opened by non-NumPy tools
3. Let NumPy add the .npy extension automatically rather than fighting it, since save() appends it if the filename doesn't already end with .npy
Tip: Use .npy, via save()/load(), for saving intermediate NumPy results within a Python workflow — it's faster to read/write and perfectly lossless, but reach for a text format like CSV specifically when the data needs to be read by other tools or inspected by a human.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
np.save("my_array.npy", arr)
loaded = np.load("my_array.npy")
print(loaded)