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

Notes<br />

Summary<br />

Blocksize<br />

Examples<br />

bsr_matrix(S, [blocksize=(R,C)])<br />

with another sparse matrix S (equivalent to S.tobsr())<br />

bsr_matrix((M, N), [blocksize=(R,C), dtype])<br />

to construct an empty matrix with shape (M, N) dtype is optional, defaulting to dtype=’d’.<br />

bsr_matrix((data, ij), [blocksize=(R,C), shape=(M, N)])<br />

where data and ij satisfy a[ij[0, k], ij[1, k]] = data[k]<br />

bsr_matrix((data, indices, indptr), [shape=(M, N)])<br />

is the standard BSR representation where the block column indices for row i are stored in<br />

indices[indptr[i]:indices[i+1]] and their corresponding block values are stored in<br />

data[ indptr[i]: indptr[i+1] ]. If the shape parameter is not supplied, the matrix<br />

dimensions are inferred from the index arrays.<br />

• The Block Compressed Row (BSR) format is very similar to the Compressed Sparse Row (CSR)<br />

format. BSR is appropriate for sparse matrices with dense sub matrices like the last example below.<br />

Block matrices often arise in vector-valued finite element discretizations. In such cases, BSR is<br />

considerably more efficient than CSR and CSC for many sparse arithmetic operations.<br />

• The blocksize (R,C) must evenly divide the shape of the matrix (M,N). That is, R and C must satisfy<br />

the relationship M % R = 0 and N % C = 0.<br />

• If no blocksize is specified, a simple heuristic is applied to determine an appropriate blocksize.<br />

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

>>> from <strong>scipy</strong> import *<br />

>>> bsr_matrix( (3,4), dtype=int8 ).todense()<br />

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

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

[0, 0, 0, 0]], dtype=int8)<br />

>>> row = array([0,0,1,2,2,2])<br />

>>> col = array([0,2,2,0,1,2])<br />

>>> data = array([1,2,3,4,5,6])<br />

>>> bsr_matrix( (data,(row,col)), shape=(3,3) ).todense()<br />

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

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

[4, 5, 6]])<br />

>>> indptr = array([0,2,3,6])<br />

>>> indices = array([0,2,2,0,1,2])<br />

>>> data = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)<br />

>>> bsr_matrix( (data,indices,indptr), shape=(6,6) ).todense()<br />

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

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

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

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

362 Chapter 3. Reference

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

Saved successfully!

Ooh no, something went wrong!