statsmodels.iolib.foreign.savetxt¶
-
statsmodels.iolib.foreign.savetxt(fname, X, names=None, fmt='%.18e', delimiter=' ')[source]¶ Save an array to a text file.
This is just a copy of numpy.savetxt patched to support structured arrays or a header of names. Does not include py3 support now in savetxt.
- Parameters
- fname
filenameorfilehandle If the filename ends in
.gz, the file is automatically saved in compressed gzip format. loadtxt understands gzipped files transparently.- Xarray_like
Data to be saved to a text file.
- names
list,optional If given names will be the column header in the text file. If None and X is a structured or recarray then the names are taken from X.dtype.names.
- fmt
stror sequenceofstrs A single format (%10.5f), a sequence of formats, or a multi-format string, e.g. ‘Iteration %d – %10.5f’, in which case delimiter is ignored.
- delimiter
str Character separating columns.
- fname
See also
saveSave an array to a binary file in NumPy
.npyformatsavezSave several arrays into a
.npzcompressed archive
Notes
Further explanation of the fmt parameter (
%[flag]width[.precision]specifier):- flags:
-: left justify+: Forces to preceed result with + or -.0: Left pad the number with zeros instead of space (see width).- width:
Minimum number of characters to be printed. The value is not truncated if it has more characters.
- precision:
For integer specifiers (eg.
d,i,o,x), the minimum number of digits.For
e, Eandfspecifiers, the number of digits to print after the decimal point.For
gandG, the maximum number of significant digits.For
s, the maximum number of characters.
- specifiers:
c: characterdori: signed decimal integereorE: scientific notation witheorE.f: decimal floating pointg,G: use the shorter ofe,Eorfo: signed octals: str of charactersu: unsigned decimal integerx,X: unsigned hexadecimal integer
This explanation of
fmtis not complete, for an exhaustive specification see [1].References
- 1
Format Specification Mini-Language, Python Documentation.
Examples
>>> savetxt('test.out', x, delimiter=',') # x is an array >>> savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays >>> savetxt('test.out', x, fmt='%1.4e') # use exponential notation