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.

class dok_matrix(arg1, shape=None, dtype=None, copy=False)<br />

Dictionary Of Keys based sparse matrix.<br />

This is an efficient structure for constructing sparse matrices incrementally.<br />

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

Notes<br />

dok_matrix(D)<br />

with a dense matrix, D<br />

dok_matrix(S)<br />

with a sparse matrix, S<br />

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

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

create the matrix with initial shape (M,N) dtype is optional, defaulting to dtype=’d’<br />

Allows for efficient O(1) access of individual elements. Duplicates are not allowed. Can be efficiently converted<br />

to a coo_matrix once constructed.<br />

Examples<br />

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

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

>>> S = dok_matrix((5,5), dtype=float32)<br />

>>> for i in range(5):<br />

>>> for j in range(5):<br />

>>> S[i,j] = i+j # Update element<br />

Methods<br />

asformat(format) Return this matrix in a given sparse format<br />

asfptype() Upcast matrix to a floating point format (if necessary)<br />

astype(t)<br />

clear D.clear() -> None. Remove all items from D.<br />

conj()<br />

conjtransp() Return the conjugate transpose<br />

conjugate()<br />

copy()<br />

diagonal() Returns the main diagonal of the matrix<br />

dot(*args, **kwds) dot is deprecated!<br />

fromkeys<br />

get(key[, default]) This overrides the dict.get method, providing type checking<br />

getH()<br />

get_shape()<br />

getcol(j) Returns a copy of column j of the matrix, as an (m x 1) sparse<br />

getdata(*args, **kwds) getdata is deprecated!<br />

getformat()<br />

getmaxprint()<br />

getnnz()<br />

getrow(i) Returns a copy of row i of the matrix, as a (1 x n) sparse<br />

has_key D.has_key(k) -> True if D has a key k, else False<br />

items D.items() -> list of D’s (key, value) pairs, as 2-tuples<br />

iteritems D.iteritems() -> an iterator over the (key, value) items of D<br />

Continued on next page<br />

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

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

Saved successfully!

Ooh no, something went wrong!