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

csc_matrix(S)<br />

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

csc_matrix((M, N), [dtype])<br />

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

csc_matrix((data, ij), [shape=(M, N)])<br />

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

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

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

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

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

are inferred from the index arrays.<br />

Advantages of the CSC format<br />

• efficient arithmetic operations CSC + CSC, CSC * CSC, etc.<br />

• efficient column slicing<br />

• fast matrix vector products (CSR, BSR may be faster)<br />

Disadvantages of the CSC format<br />

Examples<br />

• slow row slicing operations (consider CSR)<br />

• changes to the sparsity structure are expensive (consider LIL or DOK)<br />

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

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

>>> csc_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,2,2,0,1,2])<br />

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

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

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

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

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

[2, 3, 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])<br />

>>> csc_matrix( (data,indices,indptr), shape=(3,3) ).todense()<br />

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

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

[2, 3, 6]])<br />

350 Chapter 3. Reference

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

Saved successfully!

Ooh no, something went wrong!