w3resource

NumPy: Input and output routines

Input and output routines

NumPy binary files (NPY, NPZ)
Name Description Syntax
load() Load arrays or pickled objects from .npy, .npz or pickled files. numpy.load(file, mmap_mode=None, allow_pickle=True, fix_imports=True,
encoding='ASCII')
save() Save an array to a binary file in NumPy .npy format. numpy.save(file, arr, allow_pickle=True, fix_imports=True)
savez() Save several arrays into a single file in uncompressed .npz format. numpy.savez(file, *args, **kwds)
savez_compressed() Save several arrays into a single file in compressed .npz format. numpy.savez_compressed(file, *args, **kwds)
Text files
Name Description Syntax
loadtxt() Load data from a text file. numpy.loadtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None,
converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes')
savetxt() Save an array to a text file. numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='',
comments='# ', encoding=None)
genfromtxt() Load data from a text file, with missing values handled as specified. numpy.genfromtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None, skip_header=0, skip_footer=0, converters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, replace_space='_', autostrip=False, case_sensitive=True, defaultfmt='f%i', unpack=None, usemask=False, loose=True, invalid_raise=True, max_rows=None, encoding='bytes')
fromregex() Construct an array from a text file, using regular expression parsing. numpy.fromregex(file, regexp, dtype, encoding=None)
fromstring() A new 1-D array initialized from raw binary or text data in a string. numpy.fromstring(string, dtype=float, count=-1, sep='')
ndarray.tofile() Write array to a file as text or binary (default). ndarray.tofile(fid, sep="", format="%s")
ndarray.tolist() Return the array as a (possibly nested) list ndarray.tolist()
Raw binary files
Name Description Syntax
fromfile() Construct an array from data in a text or binary file. numpy.fromfile(file, dtype=float, count=-1, sep='')
String formatting
Name Description Syntax
array2string() Return a string representation of an array. numpy.array2string(a, max_line_width=None, precision=None, suppress_small=None, separator=' ', prefix='', style=<no value>, formatter=None, threshold=None, edgeitems=None, sign=None, floatmode=None, suffix='', **kwarg)
array_repr() Return the string representation of an array. numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None)
array_str() Return a string representation of the data in an array. numpy.array_str(a, max_line_width=None, precision=None, suppress_small=None)
format_float_positional() Format a floating-point scalar as a decimal string in positional notation. numpy.format_float_positional(x, precision=None, unique=True, fractional=True, trim='k',
sign=False, pad_left=None, pad_right=None)
format_float_scientific() Format a floating-point scalar as a decimal string in scientific notation. numpy.format_float_scientific(x, precision=None, unique=True, trim='k',
sign=False, pad_left=None, exp_digits=None)
Memory mapping files
Name Description Syntax
memmap() Create a memory-map to an array stored in a binary file on disk. class numpy.memmap
Text formatting options
set_printoptions() Set printing options. numpy.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None,
suppress=None, nanstr=None, infstr=None, formatter=None, sign=None, floatmode=None, **kwarg)
get_printoptions() Return the current print options. numpy.get_printoptions()
set_string_function() Set a Python function to be used when pretty printing arrays. numpy.set_string_function(f, repr=True)
printoptions() Context manager for setting print options. numpy.printoptions(*args, **kwargs)
Base-n representations
Name Description Syntax
binary_repr() Return the binary representation of the input number as a string. numpy.binary_repr(num, width=None)
base_repr() Return a string representation of a number in the given base system. numpy.base_repr(number, base=2, padding=0)
Data sources
DataSource() A generic data source file (file, http, ftp, ...). class numpy.DataSource(destpath='.')
Binary Format Description
lib.format() A simple format for saving numpy arrays to disk with the full information about them.  


Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/numpy/input-and-output/index.php