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

density()<br />

Return the density <strong>of</strong> the matrix.<br />

By density we underst<strong>and</strong> the ratio <strong>of</strong> the number <strong>of</strong> nonzero positions <strong>and</strong> the self.nrows() * self.ncols(),<br />

i.e. the number <strong>of</strong> possible nonzero positions.<br />

EXAMPLES:<br />

sage: a = matrix([[],[],[],[]], sparse=True); a.density()<br />

0<br />

sage: a = matrix(5000,5000,{(1,2): 1}); a.density()<br />

1/25000000<br />

determinant(**kwds)<br />

Return the determinant <strong>of</strong> this matrix.<br />

Note: the generic sparse determinant implementation in <strong>Sage</strong> is to just compute the determinant <strong>of</strong><br />

the corresponding dense matrix, so this could use a lot <strong>of</strong> memory. In particular, for this matrix, the<br />

determinant will be computed using a dense algorithm.<br />

EXAMPLES:<br />

sage: A = matrix(ZZ, 4, range(16), sparse=True)<br />

sage: B = A + identity_matrix(ZZ, 4, sparse=True)<br />

sage: B.det()<br />

-49<br />

matrix_from_rows_<strong>and</strong>_columns(rows, columns)<br />

Return the matrix constructed from self from the given rows <strong>and</strong> columns.<br />

EXAMPLES:<br />

sage: M = MatrixSpace(Integers(8),3,3, sparse=True)<br />

sage: A = M(range(9)); A<br />

[0 1 2]<br />

[3 4 5]<br />

[6 7 0]<br />

sage: A.matrix_from_rows_<strong>and</strong>_columns([1], [0,2])<br />

[3 5]<br />

sage: A.matrix_from_rows_<strong>and</strong>_columns([1,2], [1,2])<br />

[4 5]<br />

[7 0]<br />

Note that row <strong>and</strong> column indices can be reordered or repeated:<br />

sage: A.matrix_from_rows_<strong>and</strong>_columns([2,1], [2,1])<br />

[0 7]<br />

[5 4]<br />

For example here we take from row 1 columns 2 then 0 twice, <strong>and</strong> do this 3 times.<br />

sage: A.matrix_from_rows_<strong>and</strong>_columns([1,1,1],[2,0,0])<br />

[5 3 3]<br />

[5 3 3]<br />

[5 3 3]<br />

We can efficiently extract large submatrices:<br />

sage: A = r<strong>and</strong>om_matrix(ZZ, 100000, density=.00005, sparse=True)<br />

sage: B = A[50000:,:50000] # long time<br />

# long time (4s on sage.ma<br />

285

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

Saved successfully!

Ooh no, something went wrong!