write_arrays

sherpa.io.write_arrays(filename: str, args: Sequence[Sequence[float] | ndarray], fields: Sequence[str] | None = None, sep: str = ' ', comment: str = '#', clobber: bool = False, linebreak: str = '\n', format: str = '%g') None[source] [edit on github]

Write a list of arrays to an ASCII file.

Parameters:
  • filename (str) – The name of the file to write the array to.

  • args (array_like) – The arrays to write out.

  • fields (array_like of str) – The column names (should match the size of args if given).

  • sep (str, optional) – The separator character. The default is ' '.

  • comment (str, optional) – The comment character. The default is '#'. This is only used to write out the column names when fields is not None.

  • clobber (bool, optional) – If filename is not None, then this flag controls whether an existing file can be overwritten (True) or if it raises an exception (False, the default setting).

  • linebreak (str, optional) – Indicate a new line. The default is '\n'.

  • format (str, optional) – The format used to write out the numeric values. The default is '%g%'.

Raises:

sherpa.utils.err.IOErr – If filename already exists and clobber is False or if there is no data to write.

See also

get_ascii_data

Examples

Write the x and y arrays to the file ‘src.dat’:

>>> write_arrays('src.dat', [x, y])

Use the column names “r” and “surbri” for the columns:

>>> write_arrays('prof.txt', [x, y], fields=["r", "surbri"],
                 clobber=True)