scipy.sparse.dok_matrix

class scipy.sparse.dok_matrix(arg1, shape=None, dtype=None, copy=False)

Dictionary Of Keys based sparse matrix.

This is an efficient structure for constructing sparse matrices incrementally.

This can be instantiated in several ways:
dok_matrix(D)
with a dense matrix, D
dok_matrix(S)
with a sparse matrix, S
dok_matrix((M,N), [dtype])
create the matrix with initial shape (M,N) dtype is optional, defaulting to dtype=’d’

Notes

Allows for efficient O(1) access of individual elements. Duplicates are not allowed. Can be efficiently converted to a coo_matrix once constructed.

Examples

>>> from scipy.sparse import *
>>> from scipy import *
>>> S = dok_matrix((5,5), dtype=float32)
>>> for i in range(5):
>>>     for j in range(5):
>>>         S[i,j] = i+j # Update element

Methods

asformat
asfptype
astype
clear
conj
conjtransp
conjugate
copy Generic (shallow and deep) copying operations.
diagonal
dot
fromkeys
get
getH
get_shape
getcol
getformat
getmaxprint
getnnz
getrow
has_key
items
iteritems
iterkeys
itervalues
keys
mean
multiply
nonzero
pop
popitem
reshape
resize
set_shape
setdefault
setdiag
split
sum
take
toarray
tobsr
tocoo
tocsc
tocsr
todense
todia
todok
tolil
transpose
update
values

This Page