Save an array to a text file. Parametersfnamefilename or file handleIf the filename ends in Data to be saved to a text file. fmtstr or sequence of strs, optionalA 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. For complex X, the legal options for fmt are:
String or character separating columns. newlinestr, optionalString or character separating lines. New in version 1.5.0. headerstr, optionalString that will be written at the beginning of the file. New in version 1.7.0. footerstr, optionalString that will be written at the end of the file. New in version 1.7.0. commentsstr, optionalString that will be prepended to the New in version 1.7.0. encoding{None, str}, optionalEncoding 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’. New in version 1.14.0. See also save Save an array to a binary file in NumPy savez Save several arrays into an uncompressed savez_compressed Save several arrays into a compressed Notes Further explanation of the fmt parameter (
Minimum number of characters to be printed. The value is not truncated if it has more characters. precision:
This explanation of
References 1Format Specification Mini-Language, Python Documentation. 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 |