15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

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.

See Also:<br />

Returns<br />

L : sparse matrix<br />

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

tril<br />

lower triangle in sparse format<br />

Examples<br />

SciPy Reference Guide, Release 0.8.dev<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 />

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

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

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

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

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

8<br />

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

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

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

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

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

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

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

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

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

<br />

bmat(blocks, format=None, dtype=None)<br />

Build a sparse matrix from sparse sub-blocks<br />

Examples<br />

Parameters<br />

blocks :<br />

grid of sparse matrices with compatible shapes an entry of None implies an all-zero<br />

matrix<br />

format : sparse format of the result (e.g. “csr”)<br />

by default an appropriate sparse matrix format is returned. This choice is subject to<br />

change.<br />

>>> from <strong>scipy</strong>.sparse import coo_matrix, bmat<br />

>>> A = coo_matrix([[1,2],[3,4]])<br />

>>> B = coo_matrix([[5],[6]])<br />

>>> C = coo_matrix([[7]])<br />

>>> bmat( [[A,B],[None,C]] ).todense()<br />

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

3.14. Sparse matrices (<strong>scipy</strong>.sparse) 389

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

Saved successfully!

Ooh no, something went wrong!