numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ')[source]
Save an array to a text file.
Parameters: |
fname : filename or file handle If the filename ends in X : 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
delimiter : str, optional String or character separating columns. newline : str, optional String or character separating lines. New in version 1.5.0. header : str, optional String that will be written at the beginning of the file. New in version 1.7.0. footer : str, optional String that will be written at the end of the file. New in version 1.7.0. comments : str, optional String that will be prepended to the New in version 1.7.0. |
---|
See also
save
.npy
formatsavez
.npz
archivesavez_compressed
.npz
archiveFurther explanation of the fmt
parameter (%[flag]width[.precision]specifier
):
-
: left justify
+
: Forces to precede result with + or -.
0
: Left pad the number with zeros instead of space (see width).
d,i,o,x
), the minimum number of digits.e, E
and f
specifiers, the number of digits to print after the decimal point.g
and G
, the maximum number of significant digits.s
, the maximum number of characters.c
: character
d
or i
: signed decimal integer
e
or E
: scientific notation with e
or E
.
f
: decimal floating point
g,G
: use the shorter of e,E
or f
o
: signed octal
s
: string of characters
u
: unsigned decimal integer
x,X
: unsigned hexadecimal integer
This explanation of fmt
is not complete, for an exhaustive specification see [R280].
[R280] | (1, 2) Format Specification Mini-Language, Python Documentation. |
>>> 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
© 2008–2016 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.savetxt.html