Save an array to a text file. 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
(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
footer='', comments='# ', encoding=None)
| 1389 | |
| 1390 | @array_function_dispatch(_savetxt_dispatcher) |
| 1391 | def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', |
| 1392 | footer='', comments='# ', encoding=None): |
| 1393 | """ |
| 1394 | Save an array to a text file. |
| 1395 | |
| 1396 | Parameters |
| 1397 | ---------- |
| 1398 | fname : filename or file handle |
| 1399 | If the filename ends in ``.gz``, the file is automatically saved in |
| 1400 | compressed gzip format. `loadtxt` understands gzipped files |
| 1401 | transparently. |
| 1402 | X : 1D or 2D array_like |
| 1403 | Data to be saved to a text file. |
| 1404 | fmt : str or sequence of strs, optional |
| 1405 | A single format (%10.5f), a sequence of formats, or a |
| 1406 | multi-format string, e.g. 'Iteration %d -- %10.5f', in which |
| 1407 | case `delimiter` is ignored. For complex `X`, the legal options |
| 1408 | for `fmt` are: |
| 1409 | |
| 1410 | * a single specifier, `fmt='%.4e'`, resulting in numbers formatted |
| 1411 | like `' (%s+%sj)' % (fmt, fmt)` |
| 1412 | * a full string specifying every real and imaginary part, e.g. |
| 1413 | `' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'` for 3 columns |
| 1414 | * a list of specifiers, one per column - in this case, the real |
| 1415 | and imaginary part must have separate specifiers, |
| 1416 | e.g. `['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns |
| 1417 | delimiter : str, optional |
| 1418 | String or character separating columns. |
| 1419 | newline : str, optional |
| 1420 | String or character separating lines. |
| 1421 | |
| 1422 | .. versionadded:: 1.5.0 |
| 1423 | header : str, optional |
| 1424 | String that will be written at the beginning of the file. |
| 1425 | |
| 1426 | .. versionadded:: 1.7.0 |
| 1427 | footer : str, optional |
| 1428 | String that will be written at the end of the file. |
| 1429 | |
| 1430 | .. versionadded:: 1.7.0 |
| 1431 | comments : str, optional |
| 1432 | String that will be prepended to the ``header`` and ``footer`` strings, |
| 1433 | to mark them as comments. Default: '# ', as expected by e.g. |
| 1434 | ``numpy.loadtxt``. |
| 1435 | |
| 1436 | .. versionadded:: 1.7.0 |
| 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 | .. versionadded:: 1.14.0 |
| 1444 | |
| 1445 | |
| 1446 | See Also |
| 1447 | -------- |
| 1448 | save : Save an array to a binary file in NumPy ``.npy`` format |