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.

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

An example where the codomain is explicitly specified.<br />

sage: n = m.apply_map(lambda x:x%3, GF(3))<br />

sage: n.parent()<br />

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

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

2<br />

If we didn’t specify the codomain, the resulting matrix in the above case ends up over ZZ again:<br />

sage: n = m.apply_map(lambda x:x%3)<br />

sage: n.parent()<br />

Full MatrixSpace <strong>of</strong> 10000 by 10000 sparse matrices over Integer Ring<br />

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

2<br />

If self is subdivided, the result will be as well:<br />

sage: m = matrix(2, 2, [0, 0, 3, 0])<br />

sage: m.subdivide(None, 1); m<br />

[0|0]<br />

[3|0]<br />

sage: m.apply_map(lambda x: x*x)<br />

[0|0]<br />

[9|0]<br />

If the map sends zero to a non-zero value, then it may be useful to get the result as a dense matrix.<br />

sage: m = matrix(ZZ, 3, 3, [0] * 7 + [1,2], sparse=True); m<br />

[0 0 0]<br />

[0 0 0]<br />

[0 1 2]<br />

sage: parent(m)<br />

Full MatrixSpace <strong>of</strong> 3 by 3 sparse matrices over Integer Ring<br />

sage: n = m.apply_map(lambda x: x+polygen(QQ), sparse=False); n<br />

[ x x x]<br />

[ x x x]<br />

[ x x + 1 x + 2]<br />

sage: parent(n)<br />

Full MatrixSpace <strong>of</strong> 3 by 3 dense matrices over Univariate Polynomial Ring in x over Rational<br />

TESTS:<br />

sage: m = matrix([], sparse=True)<br />

sage: m.apply_map(lambda x: x*x) == m<br />

True<br />

sage: m.apply_map(lambda x: x*x, sparse=False).parent()<br />

Full MatrixSpace <strong>of</strong> 0 by 0 dense matrices over Integer Ring<br />

Check that we don’t unnecessarily apply phi to 0 in the sparse case:<br />

sage: m = matrix(QQ, 2, 2, range(1, 5), sparse=True)<br />

sage: m.apply_map(lambda x: 1/x)<br />

[ 1 1/2]<br />

[1/3 1/4]<br />

Test subdivisions when phi maps 0 to non-zero:<br />

sage: m = matrix(2, 2, [0, 0, 3, 0])<br />

sage: m.subdivide(None, 1); m<br />

282 Chapter 11. Base class for sparse matrices

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

Saved successfully!

Ooh no, something went wrong!