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

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

sage: M[3,range(5)]<br />

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

sage: M[3,:]<br />

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

sage: M[3,4]<br />

4<br />

sage: M[-1,:]<br />

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

sage: A = matrix(ZZ,3,4, [3, 2, -5, 0, 1, -1, 1, -4, 1, 0, 1, -3]); A<br />

[ 3 2 -5 0]<br />

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

[ 1 0 1 -3]<br />

A series <strong>of</strong> three numbers, separated by colons, like n:m:s, means numbers from n up to (but not including) m, in<br />

steps <strong>of</strong> s. So 0:5:2 means the sequence [0,2,4]:<br />

sage: A[:,0:4:2]<br />

[ 3 -5]<br />

[ 1 1]<br />

[ 1 1]<br />

sage: A[1:,0:4:2]<br />

[1 1]<br />

[1 1]<br />

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

[ 1 0 1 -3]<br />

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

[ 3 2 -5 0]<br />

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

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

[-3 1 0 1]<br />

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

[-4 -1]<br />

[-3 0]<br />

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

[-3 1]<br />

[-4 1]<br />

[ 0 -5]<br />

We can also change submatrices using these indexing features:<br />

sage: M=matrix([(1, -2, -1, -1,9), (1, 8, 6, 2,2), (1, 1, -1, 1,4), (-1, 2, -2, -1,4)]); M<br />

[ 1 -2 -1 -1 9]<br />

[ 1 8 6 2 2]<br />

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

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

Set the 2 x 2 submatrix <strong>of</strong> M, starting at row index <strong>and</strong> column index 1:<br />

sage: M[1:3,1:3] = [[1,0],[0,1]]; M<br />

[ 1 -2 -1 -1 9]<br />

3.1. Indexing 61

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

Saved successfully!

Ooh no, something went wrong!