08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER<br />

ELEVEN<br />

BASE CLASS FOR SPARSE MATRICES<br />

Base class for sparse matrices<br />

class sage.matrix.matrix_sparse.Matrix_sparse<br />

Bases: sage.matrix.matrix.Matrix<br />

The initialization routine <strong>of</strong> the Matrix base class ensures that it sets the attributes self._parent, self._base_ring,<br />

self._nrows, self._ncols. It sets the latter ones by accessing the relevant information on parent, which is <strong>of</strong>ten<br />

slower than what a more specific subclass can do.<br />

Subclasses <strong>of</strong> Matrix can safely skip calling Matrix.__init__ provided they take care <strong>of</strong> initializing these attributes<br />

themselves.<br />

The private attributes self._is_immutable <strong>and</strong> self._cache are implicitly initialized to valid values upon memory<br />

allocation.<br />

EXAMPLES:<br />

sage: import sage.matrix.matrix0<br />

sage: A = sage.matrix.matrix0.Matrix(MatrixSpace(QQ,2))<br />

sage: type(A)<br />

<br />

antitranspose()<br />

apply_map(phi, R=None, sparse=True)<br />

Apply the given map phi (an arbitrary Python function or callable object) to this matrix. If R is not given,<br />

automatically determine the base ring <strong>of</strong> the resulting matrix.<br />

INPUT: sparse – False to make the output a dense matrix; default True<br />

•phi - arbitrary Python function or callable object<br />

•R - (optional) ring<br />

OUTPUT: a matrix over R<br />

EXAMPLES:<br />

sage: m = matrix(ZZ, 10000, {(1,2): 17}, sparse=True)<br />

sage: k. = GF(9)<br />

sage: f = lambda x: k(x)<br />

sage: n = m.apply_map(f)<br />

sage: n.parent()<br />

Full MatrixSpace <strong>of</strong> 10000 by 10000 sparse matrices over Finite Field in a <strong>of</strong> size 3^2<br />

sage: n[1,2]<br />

2<br />

281

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!