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:
filenamestr

The name of the file to write the array to.

argsarray_like

The arrays to write out.

fieldsarray_like of str

The column names (should match the size of args if given).

sepstr, optional

The separator character. The default is ' '.

commentstr, optional

The comment character. The default is '#'. This is only used to write out the column names when fields is not None.

clobberbool, 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).

linebreakstr, optional

Indicate a new line. The default is '\n'.

formatstr, 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)