Login  Register

How do you save a NumPy array as a file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

How do you save a NumPy array as a file?

pythonsevenmentor
You can save a NumPy array as a file using different methods depending on the format you need. Here are some commonly used approaches:
1. Save as a .npy File (Binary Format)
The .npy format is NumPy's native binary file format, which is efficient and preserves data types.import numpy as np

# Create a sample NumPy array
arr = np.array([[1, 2, 3], [4, 5, 6]])

# Save the array to a file
np.save("array.npy", arr)

# Load the array back
loaded_arr = np.load("array.npy")
print(loaded_arr)

Link: Online Python Training in Pune