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

If subdivide is True then any row subdivisions for the two matrices are preserved, <strong>and</strong> a new subdivision<br />

is added between self <strong>and</strong> bottom. If the column divisions are identical, then they are preserved,<br />

otherwise they are discarded. When subdivide is False there is no subdivision information in the<br />

result.<br />

Warning: If subdivide is True then unequal column subdivisions will be discarded, since it<br />

would be ambiguous how to interpret them. If the subdivision behavior is not what you need, you<br />

can manage subdivisions yourself with methods like subdivisions() <strong>and</strong> subdivide(). You<br />

might also find block_matrix() or block_diagonal_matrix() useful <strong>and</strong> simpler in some<br />

instances.<br />

EXAMPLES:<br />

Stacking with a matrix.<br />

sage: A = matrix(QQ, 4, 3, range(12))<br />

sage: B = matrix(QQ, 3, 3, range(9))<br />

sage: A.stack(B)<br />

[ 0 1 2]<br />

[ 3 4 5]<br />

[ 6 7 8]<br />

[ 9 10 11]<br />

[ 0 1 2]<br />

[ 3 4 5]<br />

[ 6 7 8]<br />

Stacking with a vector.<br />

sage: A = matrix(QQ, 3, 2, [0, 2, 4, 6, 8, 10])<br />

sage: v = vector(QQ, 2, [100, 200])<br />

sage: A.stack(v)<br />

[ 0 2]<br />

[ 4 6]<br />

[ 8 10]<br />

[100 200]<br />

Errors are raised if the sizes are incompatible.<br />

sage: A = matrix(RR, [[1, 2],[3, 4]])<br />

sage: B = matrix(RR, [[10, 20, 30], [40, 50, 60]])<br />

sage: A.stack(B)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: number <strong>of</strong> columns must be the same, 2 != 3<br />

sage: v = vector(RR, [100, 200, 300])<br />

sage: A.stack(v)<br />

Traceback (most recent call last):<br />

...<br />

TypeError: number <strong>of</strong> columns must be the same, 2 != 3<br />

Setting subdivide to True will, in its simplest form, add a subdivision between self <strong>and</strong> bottom.<br />

sage: A = matrix(QQ, 2, 5, range(10))<br />

sage: B = matrix(QQ, 3, 5, range(15))<br />

sage: A.stack(B, subdivide=True)<br />

[ 0 1 2 3 4]<br />

[ 5 6 7 8 9]<br />

[--------------]<br />

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