numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ', encoding=None)

Notes

Further explanation of the :None:None:`fmt` parameter ( %[flag]width[.precision]specifier ):

Parameters

fname : filename or file handle

If the filename ends in .gz , the file is automatically saved in compressed gzip format. loadtxt understands gzipped files transparently.

X : 1D or 2D array_like

Data to be saved to a text file.

fmt : str or sequence of strs, optional

A single format (%10.5f), a sequence of formats, or a multi-format string, e.g. 'Iteration %d -- %10.5f', in which case :None:None:`delimiter` is ignored. For complex X, the legal options for :None:None:`fmt` are:

  • a single specifier, :None:None:`fmt='%.4e'`, resulting in numbers formatted like :None:None:`' (%s+%sj)' % (fmt, fmt)`

  • a full string specifying every real and imaginary part, e.g. :None:None:`' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'` for 3 columns

  • a list of specifiers, one per column - in this case, the real and imaginary part must have separate specifiers, e.g. :None:None:`['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns

delimiter : str, optional

String or character separating columns.

newline : str, optional

String or character separating lines.

versionadded
header : str, optional

String that will be written at the beginning of the file.

versionadded
footer : str, optional

String that will be written at the end of the file.

versionadded
comments : str, optional

String that will be prepended to the header and footer strings, to mark them as comments. Default: '# ', as expected by e.g. numpy.loadtxt .

versionadded
encoding : {None, str}, optional

Encoding used to encode the outputfile. Does not apply to output streams. If the encoding is something other than 'bytes' or 'latin1' you will not be able to load the file in NumPy versions < 1.14. Default is 'latin1'.

versionadded

Save an array to a text file.

See Also

save

Save an array to a binary file in NumPy .npy format

savez

Save several arrays into an uncompressed .npz archive

savez_compressed

Save several arrays into a compressed .npz archive

Examples

>>> x = y = z = np.arange(0.0,5.0,1.0)
... np.savetxt('test.out', x, delimiter=',') # X is an array
... np.savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays
... np.savetxt('test.out', x, fmt='%1.4e') # use exponential notation
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.savez numpy.save numpy.savez_compressed

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/npyio.py#1217
type: <class 'function'>
Commit: