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 />

sparse_columns(copy=True)<br />

Return a list <strong>of</strong> the columns <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: a = matrix(2,3,range(6)); a<br />

[0 1 2]<br />

[3 4 5]<br />

sage: v = a.sparse_columns(); v<br />

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

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

True<br />

TESTS:<br />

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

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

sage: m.ncols()<br />

0<br />

sage: m.columns()<br />

[]<br />

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

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

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

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

[False, False, False]<br />

sparse_matrix()<br />

If this matrix is dense, return a sparse matrix with the same entries. If this matrix is sparse, 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=False)([1,2,0,1])<br />

sage: A.is_sparse()<br />

False<br />

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

sage: B.is_sparse()<br />

True<br />

sage: A<br />

[1 2]<br />

[0 1]<br />

sage: B<br />

[1 2]<br />

[0 1]<br />

sage: A*B<br />

[1 4]<br />

[0 1]<br />

sage: A.parent()<br />

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

112 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!