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

We can use the step feature <strong>of</strong> slices to set every other column:<br />

sage: A[:,0:3:2] = 5; A<br />

[ 5 2 5 0]<br />

[ 5 -1 5 -4]<br />

[ 5 0 5 -3]<br />

sage: A[1:,0:4:2] = [[100,200],[300,400]]; A<br />

[ 5 2 5 0]<br />

[100 -1 200 -4]<br />

[300 0 400 -3]<br />

We can also count backwards to flip the matrix upside down:<br />

sage: A[::-1,:]=A; A<br />

[300 0 400 -3]<br />

[100 -1 200 -4]<br />

[ 5 2 5 0]<br />

sage: A[1:,3::-1]=[[2,3,0,1],[9,8,7,6]]; A<br />

[300 0 400 -3]<br />

[ 1 0 3 2]<br />

[ 6 7 8 9]<br />

sage: A[1:,::-2] = A[1:,::2]; A<br />

[300 0 400 -3]<br />

[ 1 3 3 1]<br />

[ 6 8 8 6]<br />

sage: A[::-1,3:1:-1] = [[4,3],[1,2],[-1,-2]]; A<br />

[300 0 -2 -1]<br />

[ 1 3 2 1]<br />

[ 6 8 3 4]<br />

We save <strong>and</strong> load a matrix:<br />

sage: A = matrix(Integers(8),3,range(9))<br />

sage: loads(dumps(A)) == A<br />

True<br />

MUTABILITY: <strong>Matrices</strong> are either immutable or not. When initially created, matrices are typically mutable, so<br />

one can change their entries. Once a matrix A is made immutable using A.set_immutable() the entries <strong>of</strong> A<br />

cannot be changed, <strong>and</strong> A can never be made mutable again. However, properties <strong>of</strong> A such as its rank, characteristic<br />

polynomial, etc., are all cached so computations involving A may be more efficient. Once A is made immutable it<br />

cannot be changed back. However, one can obtain a mutable copy <strong>of</strong> A using copy(A).<br />

EXAMPLES:<br />

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

sage: A.set_immutable()<br />

sage: copy(A) is A<br />

False<br />

The echelon form method always returns immutable matrices with known rank.<br />

EXAMPLES:<br />

sage: A = matrix(Integers(8),3,range(9))<br />

sage: A.determinant()<br />

0<br />

3.1. Indexing 63

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

Saved successfully!

Ooh no, something went wrong!