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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

sage: B.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 sparse matrices over Rational Field<br />

sage: (A*B).parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Rational Field<br />

sage: (B*A).parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Rational Field<br />

sparse_rows(copy=True)<br />

Return a list <strong>of</strong> the rows <strong>of</strong> self as sparse vectors (or free module elements).<br />

INPUT:<br />

•copy - (default: True) if True, return a copy so you can modify it safely<br />

EXAMPLES:<br />

sage: m = Mat(ZZ,3,3,sparse=True)(range(9)); m<br />

[0 1 2]<br />

[3 4 5]<br />

[6 7 8]<br />

sage: v = m.sparse_rows(); v<br />

[(0, 1, 2), (3, 4, 5), (6, 7, 8)]<br />

sage: m.sparse_rows(copy=False) is m.sparse_rows(copy=False)<br />

True<br />

sage: v[1].is_sparse()<br />

True<br />

sage: m[0,0] = 10<br />

sage: m.sparse_rows()<br />

[(10, 1, 2), (3, 4, 5), (6, 7, 8)]<br />

TESTS:<br />

Rows <strong>of</strong> sparse matrices having no rows were fixed on trac ticket #10714:<br />

sage: m = matrix(0, 10, sparse=True)<br />

sage: m.nrows()<br />

0<br />

sage: m.rows()<br />

[]<br />

Check that the returned rows are immutable as per trac ticket #14874:<br />

sage: m = Mat(ZZ,3,3,sparse=True)(range(9))<br />

sage: v = m.sparse_rows()<br />

sage: map(lambda x: x.is_mutable(), v)<br />

[False, False, False]<br />

stack(bottom, subdivide=False)<br />

Returns a new matrix formed by appending the matrix (or vector) bottom beneath self.<br />

INPUT:<br />

•bottom - a matrix, vector or free module element, whose dimensions are compatible with self.<br />

•subdivide - default: False - request the resulting matrix to have a new subdivision, separating<br />

self from bottom.<br />

OUTPUT:<br />

A new matrix formed by appending bottom beneath self. If bottom is a vector (or free module<br />

element) then in this context it is appropriate to consider it as a row vector. (The code first converts a<br />

vector to a 1-row matrix.)<br />

113

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

Saved successfully!

Ooh no, something went wrong!