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: A = matrix(QQ, 4, range(20))<br />

sage: A.with_swapped_columns(1, 2)<br />

[ 0 2 1 3 4]<br />

[ 5 7 6 8 9]<br />

[10 12 11 13 14]<br />

[15 17 16 18 19]<br />

Trying to swap a column with itself will succeed, but still return a new matrix.<br />

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

sage: B = A.with_swapped_columns(2, 2)<br />

sage: A == B<br />

True<br />

sage: A is B<br />

False<br />

The column specifications are checked.<br />

sage: A = matrix(4, range(20))<br />

sage: A.with_swapped_columns(-1, 2)<br />

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

...<br />

IndexError: matrix column index out <strong>of</strong> range<br />

sage: A.with_swapped_columns(2, 5)<br />

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

...<br />

IndexError: matrix column index out <strong>of</strong> range<br />

with_swapped_rows(r1, r2)<br />

Swap rows r1 <strong>and</strong> r2 <strong>of</strong> self <strong>and</strong> return a new matrix.<br />

INPUT:<br />

•r1, r2 - integers specifying rows <strong>of</strong> self to interchange<br />

OUTPUT:<br />

A new matrix, identical to self except that rows r1 <strong>and</strong> r2 are swapped.<br />

EXAMPLES:<br />

Remember that rows are numbered starting from zero.<br />

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

sage: A.with_swapped_rows(1, 2)<br />

[ 0 1 2 3 4]<br />

[10 11 12 13 14]<br />

[ 5 6 7 8 9]<br />

[15 16 17 18 19]<br />

Trying to swap a row with itself will succeed, but still return a new matrix.<br />

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

sage: B = A.with_swapped_rows(2, 2)<br />

sage: A == B<br />

True<br />

sage: A is B<br />

False<br />

The row specifications are checked.<br />

94 Chapter 5. Base class for matrices, part 0

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

Saved successfully!

Ooh no, something went wrong!