AnnData.write(filename=None, compression=None, compression_opts=None, force_dense=None)

Write .h5ad-formatted hdf5 file.


Setting compression to 'gzip' can save disk space but will slow down writing and subsequent reading. Prior to v0.6.16, this was the default for parameter compression.

Generally, if you have sparse data that are stored as a dense matrix, you can dramatically improve performance and reduce disk space by converting to a csr_matrix:

from scipy.sparse import csr_matrix
adata.X = csr_matrix(adata.X)
filename : PathLike, NoneOptional[PathLike]

Filename of data file. Defaults to backing file.

compression : None, {'gzip', 'lzf'} (default: None)

See the h5py Filter pipeline.

compression_opts : int, Any, NoneUnion[int, Any, None]

See the h5py Filter pipeline.

force_dense : bool, NoneOptional[bool]

Write sparse data as a dense matrix. Defaults to True if object is backed, otherwise to False.