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: m = Mat(ZZ,3,3)(range(9))<br />

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

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

[False, False, False]<br />

dense_matrix()<br />

If this matrix is sparse, return a dense matrix with the same entries. If this matrix is dense, return this<br />

matrix (not a copy).<br />

Note: The definition <strong>of</strong> “dense” <strong>and</strong> “sparse” in <strong>Sage</strong> have nothing to do with the number <strong>of</strong> nonzero<br />

entries. Sparse <strong>and</strong> dense are properties <strong>of</strong> the underlying representation <strong>of</strong> the matrix.<br />

EXAMPLES:<br />

sage: A = MatrixSpace(QQ,2, sparse=True)([1,2,0,1])<br />

sage: A.is_sparse()<br />

True<br />

sage: B = A.dense_matrix()<br />

sage: B.is_sparse()<br />

False<br />

sage: A*B<br />

[1 4]<br />

[0 1]<br />

sage: A.parent()<br />

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

sage: B.parent()<br />

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

In <strong>Sage</strong>, the product <strong>of</strong> a sparse <strong>and</strong> a dense matrix is always dense:<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 />

TESTS:<br />

Make sure that subdivisions are preserved when switching between dense <strong>and</strong> sparse matrices:<br />

sage: a = matrix(ZZ, 3, range(9))<br />

sage: a.subdivide([1,2],2)<br />

sage: a.subdivisions()<br />

([1, 2], [2])<br />

sage: b = a.sparse_matrix().dense_matrix()<br />

sage: b.subdivisions()<br />

([1, 2], [2])<br />

dense_rows(copy=True)<br />

Return list <strong>of</strong> the dense rows <strong>of</strong> self.<br />

INPUT:<br />

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

vectors in the copy should not be modified since they are mutable!)<br />

EXAMPLES:<br />

sage: m = matrix(3, range(9)); m<br />

[0 1 2]<br />

104 Chapter 6. Base class for matrices, part 1

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

Saved successfully!

Ooh no, something went wrong!