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.

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

This can be instantiated in several ways:<br />

Notes<br />

coo_matrix(D)<br />

with a dense matrix D<br />

coo_matrix(S)<br />

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

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

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

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

The arguments ‘data’ and ‘ij’ represent three arrays:<br />

1. data[:] the entries of the matrix, in any order<br />

2. ij[0][:] the row indices of the matrix entries<br />

3. ij[1][:] the column indices of the matrix entries<br />

Where A[ij[0][k], ij[1][k] = data[k]. When shape is not specified, it is inferred from<br />

the index arrays<br />

Advantages of the COO format<br />

• facilitates fast conversion among sparse formats<br />

• permits duplicate entries (see example)<br />

• very fast conversion to and from CSR/CSC formats<br />

Disadvantages of the COO format<br />

Intended Usage<br />

Examples<br />

• does not directly support:<br />

– arithmetic operations<br />

– slicing<br />

• COO is a fast format for constructing sparse matrices<br />

• Once a matrix has been constructed, convert to CSR or CSC format for fast arithmetic and matrix<br />

vector operations<br />

• By default when converting to CSR or CSC format, duplicate (i,j) entries will be summed together.<br />

This facilitates efficient construction of finite element matrices and the like. (see example)<br />

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

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

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

376 Chapter 3. Reference

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

Saved successfully!

Ooh no, something went wrong!