15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SciPy Reference Guide, Release 0.8.dev<br />

See Also:<br />

Returns<br />

L : sparse matrix<br />

Lower triangular portion of A in sparse format.<br />

triu<br />

upper triangle in sparse format<br />

Examples<br />

>>> from <strong>scipy</strong>.sparse import csr_matrix<br />

>>> A = csr_matrix( [[1,2,0,0,3],[4,5,0,6,7],[0,0,8,9,0]], dtype=’int32’ )<br />

>>> A.todense()<br />

matrix([[1, 2, 0, 0, 3],<br />

[4, 5, 0, 6, 7],<br />

[0, 0, 8, 9, 0]])<br />

>>> tril(A).todense()<br />

matrix([[1, 0, 0, 0, 0],<br />

[4, 5, 0, 0, 0],<br />

[0, 0, 8, 0, 0]])<br />

>>> tril(A).nnz<br />

4<br />

>>> tril(A, k=1).todense()<br />

matrix([[1, 2, 0, 0, 0],<br />

[4, 5, 0, 0, 0],<br />

[0, 0, 8, 9, 0]])<br />

>>> tril(A, k=-1).todense()<br />

matrix([[0, 0, 0, 0, 0],<br />

[4, 0, 0, 0, 0],<br />

[0, 0, 0, 0, 0]])<br />

>>> tril(A, format=’csc’)<br />

<br />

triu(A, k=0, format=None)<br />

Return the upper triangular portion of a matrix in sparse format<br />

Returns the elements on or above the k-th diagonal of the matrix A.<br />

• k = 0 corresponds to the main diagonal<br />

• k > 0 is above the main diagonal<br />

• k < 0 is below the main diagonal<br />

Parameters<br />

A : dense or sparse matrix<br />

Matrix whose upper trianglar portion is desired.<br />

k : integer<br />

The bottom-most diagonal of the upper triangle.<br />

format : string<br />

Sparse format of the result, e.g. format=”csr”, etc.<br />

388 Chapter 3. Reference

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

Saved successfully!

Ooh no, something went wrong!