### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Sparse matrices (`scipy.sparse`) »

# 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 instatiated 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

### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Sparse matrices (`scipy.sparse`) »