NumPy Input and Output: save() function
The Save() function is used to save an array to a binary file in NumPy .npy format.
numpy.save(file, arr, allow_pickle=True, fix_imports=True)
|file||File or filename to which the data is saved. If file is a file-object, then the filename is unchanged.
If file is a string or Path, a .npy extension will be appended to the file name if it does not already have one.
file, str, or pathlib.Path
|arr||Array data to be saved.
|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,
for example if the stored objects require libraries that are not available, and not all pickled data is compatible between Python 2 and Python 3).
|fix_imports||Only useful in forcing objects in object arrays on Python 3 to be pickled in a Python 2 compatible way.
If fix_imports is True, pickle will try to map the new Python 3 names to the old module names used in Python 2,
so that the pickle data stream is readable with Python 2.
For a description of the .npy format, see numpy.lib.format.
NumPy.save() method Example:
Store data to disk, and load it again:
>>> import numpy as np >>> from tempfile import TemporaryFile >>> outfile = TemporaryFile() >>> a = np.arange(12) >>> np.save(outfile, a) >>> outfile.seek(0) # Only needed here to simulate closing & reopening file >>> np.load(outfile)
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
Python - NumPy Code Editor:
- Exercises: Weekly Top 16 Most Popular Topics
- SQL Exercises, Practice, Solution - JOINS
- SQL Exercises, Practice, Solution - SUBQUERIES
- Java Array: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : Conditional Statement
- HR Database - SORT FILTER: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : String
- Python Data Types: Dictionary - Exercises, Practice, Solution
- Python Programming Puzzles - Exercises, Practice, Solution
- C++ Array: Exercises, Practice, Solution
- C# Sharp Basic Algorithm: Exercises, Practice, Solution
- Python Lambda - Exercises, Practice, Solution
- Python Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools