MCPcopy Index your code
hub / github.com/numpy/numpy / savetxt

Function savetxt

numpy/lib/_npyio_impl.py:1399–1628  ·  view source on GitHub ↗

Save an array to a text file. Parameters ---------- fname : filename, file handle or pathlib.Path If the filename ends in ``.gz``, the file is automatically saved in compressed gzip format. `loadtxt` understands gzipped files transparently. X : 1D or 2D

(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
            footer='', comments='# ', encoding=None)

Source from the content-addressed store, hash-verified

1397
1398@array_function_dispatch(_savetxt_dispatcher)
1399def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
1400 footer='', comments='# ', encoding=None):
1401 """
1402 Save an array to a text file.
1403
1404 Parameters
1405 ----------
1406 fname : filename, file handle or pathlib.Path
1407 If the filename ends in ``.gz``, the file is automatically saved in
1408 compressed gzip format. `loadtxt` understands gzipped files
1409 transparently.
1410 X : 1D or 2D array_like
1411 Data to be saved to a text file.
1412 fmt : str or sequence of strs, optional
1413 A single format (%10.5f), a sequence of formats, or a
1414 multi-format string, e.g. 'Iteration %d -- %10.5f', in which
1415 case `delimiter` is ignored. For complex `X`, the legal options
1416 for `fmt` are:
1417
1418 * a single specifier, ``fmt='%.4e'``, resulting in numbers formatted
1419 like ``' (%s+%sj)' % (fmt, fmt)``
1420 * a full string specifying every real and imaginary part, e.g.
1421 ``' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'`` for 3 columns
1422 * a list of specifiers, one per column - in this case, the real
1423 and imaginary part must have separate specifiers,
1424 e.g. ``['%.3e + %.3ej', '(%.15e%+.15ej)']`` for 2 columns
1425 delimiter : str, optional
1426 String or character separating columns.
1427 newline : str, optional
1428 String or character separating lines.
1429 header : str, optional
1430 String that will be written at the beginning of the file.
1431 footer : str, optional
1432 String that will be written at the end of the file.
1433 comments : str, optional
1434 String that will be prepended to the ``header`` and ``footer`` strings,
1435 to mark them as comments. Default: '# ', as expected by e.g.
1436 ``numpy.loadtxt``.
1437 encoding : {None, str}, optional
1438 Encoding used to encode the outputfile. Does not apply to output
1439 streams. If the encoding is something other than 'bytes' or 'latin1'
1440 you will not be able to load the file in NumPy versions < 1.14. Default
1441 is 'latin1'.
1442
1443 See Also
1444 --------
1445 save : Save an array to a binary file in NumPy ``.npy`` format
1446 savez : Save several arrays into an uncompressed ``.npz`` archive
1447 savez_compressed : Save several arrays into a compressed ``.npz`` archive
1448
1449 Notes
1450 -----
1451 Further explanation of the `fmt` parameter
1452 (``%[flag]width[.precision]specifier``):
1453
1454 flags:
1455 ``-`` : left justify
1456

Callers

nothing calls this directly

Calls 10

writeMethod · 0.95
closeMethod · 0.95
_is_string_likeFunction · 0.85
openFunction · 0.85
WriteWrapClass · 0.85
joinMethod · 0.80
replaceMethod · 0.80
closeMethod · 0.45
openMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…