io.mmio

Matrix Market I/O in Python. See http://math.nist.gov/MatrixMarket/formats.html for information about the Matrix Market format.

Module Contents

Classes

MMFile(self,**kwargs)

Functions

mminfo(source) Return size and storage parameters from Matrix Market file-like ‘source’.
mmread(source) Reads the contents of a Matrix Market file-like ‘source’ into a matrix.
mmwrite(target,a,comment=”“,field=None,precision=None,symmetry=None) Writes the sparse or dense array a to Matrix Market file-like target.
_is_fromfile_compatible(stream) Check whether stream is compatible with numpy.fromfile.
mminfo(source)

Return size and storage parameters from Matrix Market file-like ‘source’.

source : str or file-like
Matrix Market filename (extension .mtx) or open file-like object
rows : int
Number of matrix rows.
cols : int
Number of matrix columns.
entries : int
Number of non-zero entries of a sparse matrix or rows*cols for a dense matrix.
format : str
Either ‘coordinate’ or ‘array’.
field : str
Either ‘real’, ‘complex’, ‘pattern’, or ‘integer’.
symmetry : str
Either ‘general’, ‘symmetric’, ‘skew-symmetric’, or ‘hermitian’.
mmread(source)

Reads the contents of a Matrix Market file-like ‘source’ into a matrix.

source : str or file-like
Matrix Market filename (extensions .mtx, .mtz.gz) or open file-like object.
a : ndarray or coo_matrix
Dense or sparse matrix depending on the matrix format in the Matrix Market file.
mmwrite(target, a, comment="", field=None, precision=None, symmetry=None)

Writes the sparse or dense array a to Matrix Market file-like target.

target : str or file-like
Matrix Market filename (extension .mtx) or open file-like object.
a : array like
Sparse or dense 2D array.
comment : str, optional
Comments to be prepended to the Matrix Market file.
field : None or str, optional
Either ‘real’, ‘complex’, ‘pattern’, or ‘integer’.
precision : None or int, optional
Number of digits to display for real or complex values.
symmetry : None or str, optional
Either ‘general’, ‘symmetric’, ‘skew-symmetric’, or ‘hermitian’. If symmetry is None the symmetry type of ‘a’ is determined by its values.
class MMFile(**kwargs)
rows()
cols()
entries()
format()
field()
symmetry()
has_symmetry()
_validate_format(format)
_validate_field(field)
_validate_symmetry(symmetry)
reader()
writer()
info(source)

Return size, storage parameters from Matrix Market file-like ‘source’.

source : str or file-like
Matrix Market filename (extension .mtx) or open file-like object
rows : int
Number of matrix rows.
cols : int
Number of matrix columns.
entries : int
Number of non-zero entries of a sparse matrix or rows*cols for a dense matrix.
format : str
Either ‘coordinate’ or ‘array’.
field : str
Either ‘real’, ‘complex’, ‘pattern’, or ‘integer’.
symmetry : str
Either ‘general’, ‘symmetric’, ‘skew-symmetric’, or ‘hermitian’.
_open(mode="rb")

Return an open file stream for reading based on source.

If source is a file name, open it (after trying to find it with mtx and gzipped mtx extensions). Otherwise, just return source.

filespec : str or file-like
String giving file name or file-like object
mode : str, optional
Mode with which to open file, if filespec is a file name.
fobj : file-like
Open file-like object.
close_it : bool
True if the calling function should close this file when done, false otherwise.
_get_symmetry()
_field_template(precision)
__init__(**kwargs)
read(source)

Reads the contents of a Matrix Market file-like ‘source’ into a matrix.

source : str or file-like
Matrix Market filename (extensions .mtx, .mtz.gz) or open file object.
a : ndarray or coo_matrix
Dense or sparse matrix depending on the matrix format in the Matrix Market file.
write(target, a, comment="", field=None, precision=None, symmetry=None)

Writes sparse or dense array a to Matrix Market file-like target.

target : str or file-like
Matrix Market filename (extension .mtx) or open file-like object.
a : array like
Sparse or dense 2D array.
comment : str, optional
Comments to be prepended to the Matrix Market file.
field : None or str, optional
Either ‘real’, ‘complex’, ‘pattern’, or ‘integer’.
precision : None or int, optional
Number of digits to display for real or complex values.
symmetry : None or str, optional
Either ‘general’, ‘symmetric’, ‘skew-symmetric’, or ‘hermitian’. If symmetry is None the symmetry type of ‘a’ is determined by its values.
_init_attrs(**kwargs)

Initialize each attributes with the corresponding keyword arg value or a default of None

_parse_header(stream)
_parse_body(stream)
_write(stream, a, comment="", field=None, precision=None, symmetry=None)
_is_fromfile_compatible(stream)

Check whether stream is compatible with numpy.fromfile.

Passing a gzipped file object to fromfile/fromstring doesn’t work with Python3.