NumPy save() Method | Save Array to a File Last Updated : 02 Feb, 2024 Comments Improve Suggest changes Like Article Like Report The NumPy save() method is used to store the input array in a binary file with the 'npy extension' (.npy). Example: Python3 import numpy as np a = np.arange(5) np.save('array_file', a) SyntaxSyntax: numpy.save(file, arr, allow_pickle=True, fix_imports=True) Parameters: file: File or filename to which the data is saved. If the file is a string or Path, a .npy extension will be appended to the file name if it does not already have one. If the file is a file object, then the filename is unchanged. allow_pickle : Allow saving object arrays using Python pickles. Reasons for disallowing pickles include security (loading pickled data can execute arbitrary code) and portability (pickled objects may not be loadable on different Python installations). Default: True fix_imports : Only useful in forcing objects in object arrays on Python 3 to be pickled in a Python 2 compatible way. arr : Array data to be saved. Returns: Stores the input array in a disk file with '.npy' extension. ExamplesLet's understand the workings of numpy.save() method in these Python code and know how to use save() method of NumPy library. To use numpy.save() function, you just need to pass the file name and array in the function. Example 1 Python3 # Python program explaining # save() function import numpy as geek a = geek.arange(5) # a is printed. print("a is:") print(a) # the array is saved in the file geekfile.npy geek.save('geekfile', a) print("the array is saved in the file geekfile.npy") Output : a is: [0 1 2 3 4] the array is saved in the file geekfile.npy Example 2 Python3 # Python program explaining # save() function import numpy as geek # the array is loaded into b b = geek.load('geekfile.npy') print("b is:") print(b) # b is printed from geekfile.npy print("b is printed from geekfile.npy") Output : b is: [0 1 2 3 4] b is printed from geekfile.npy Comment More infoAdvertise with us Next Article NumPy save() Method | Save Array to a File A ArkadipGhosh Follow Improve Article Tags : Python Python-numpy Python numpy-io Practice Tags : python Similar Reads How to save a NumPy array to a text file? When working with data it's important to know how to save NumPy arrays to text files for storage, sharing and further analysis. There are different ways from manual file handling to using specialized NumPy functions. In this article, we will see how to save a NumPy array to a text fileMethod 1: Usin 3 min read How To Save Multiple Numpy Arrays NumPy is a powerful Python framework for numerical computing that supports massive, multi-dimensional arrays and matrices and offers a number of mathematical functions for modifying the arrays. It is an essential store for Python activities involving scientific computing, data analysis, and machine 3 min read Saving and loading NumPy Arrays The savetxt() and loadtxt() functions in NumPy are primarily designed for 1D and 2D arrays (text files with row/column format). When dealing with a 3D NumPy array, these functions can be a bit limited because they cannot directly handle the 3D structure. However, you can reshape the 3D array into a 3 min read Convert a NumPy array into a CSV file After completing your data science or data analysis project, you might want to save the data or share it with others. Exporting a NumPy array to a CSV file is the most common way of sharing data. CSV file format is the easiest and most useful format for storing data and is convenient to share with o 3 min read Wand save() method in Python Whenever we manipulate an image and want to preserve image for further image, we use save() function. save() function saves the image into the file or filename. It saves the final manipulated image in your disk. Syntax :Python3 # image manipulation code wand.image.save(file = file_object or filename 2 min read Like