savetxt_matrix

mdtools.file_handler.savetxt_matrix(fname, data, var1, var2, init_values1=None, init_values2=None, upper_left=0, fmt='%16.9e', delimiter=' ', newline='\n', header='', footer='', comments='# ', encoding=None, rename=True)[source]

Save a data matrix to a text file.

Write data that are a function of two independent variables, var1 and var2, as a matrix to a text file using mdtools.file_handler.savetxt(). The dependency of the data from var1 is represented by the rows and the dependency from var2 is represented by the columns.

Parameters
  • fname (str) – The name of the file to create.

  • data (array_like) – 2-dimensional array of data to be saved. Must be of shape (n, m), where n is the number of samples of the first independent variable (depicted row wise) and m is the mumber of samples of the second independent variable (depicted column wise).

  • var1 (array_like) – Array of shape (n,) containing the values of the first independent variable at which the data were sampled.

  • var2 (array_like) – Array of shape (m,) containing the values of the second independent variable at which the data were sampled.

  • init_values1 (array_like) – If supplied, the values stored in this array will be handled as special initial data values corresponding to the very first value in var1. Must be an array of shape (m,), whereas data must then be of shape (n-1, m).

  • init_values2 (array_like) – If supplied, the values stored in this array will be handled as special initial data values corresponding to the very first value in var2. Must be an array of shape (n,), whereas data must then be of shape (n, m-1).

  • upper_left (scalar) – Value to put in the upper left corner of the final data matrix. Usually, this value is meaningless and set to zero.

  • fmt (str or sequence of strs, optional) – Format specifier. See mdtools.file_handler.savetxt() for more details.

  • delimiter (str, optional) – String or character separating columns.

  • newline (str, optional) – String or character separating lines.

  • header (str, optional) – String that will be written at the beginning of the file, additional to the standard MDTools header. See mdtools.file_handler.header_str() for more details.

  • footer (str, optional) – String that will be written at the end of the file.

  • comments (str, optional) – String that will be prepended to the header and footer strings, to mark them as comments.

  • encoding ({None, str}, optional) – Encoding used to encode the outputfile. Does not apply to output streams. See mdtools.file_handler.savetxt() for more details.

  • rename (bool, optional) – If True and a file called fname already exists, rename it to 'fname.bak_timestamp'. See mdtools.file_handler.backup() for more details.

See also

mdtools.file_handler.savetxt()

Save an array to a text file

mdtools.file_handler.write_matrix_block()

Save a data matrix to a text file by appending the file

mdtools.file_handler.backup()

Backup a file by renaming it

Notes

Internally, this function calls mdtools.file_handler.savetxt().