class_docstr: 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'
  
  Attributes
  ----------
  dtype : dtype
      Data type of the matrix
  shape : 2-tuple
      Shape of the matrix
  ndim : int
      Number of dimensions (this is always 2)
  nnz
      Number of nonzero elements
  
  Notes
  -----
  
  Sparse matrices can be used in arithmetic operations: they support
  addition, subtraction, multiplication, division, and matrix power.
  
  Allows for efficient O(1) access of individual elements.
  Duplicates are not allowed.
  Can be efficiently converted to a coo_matrix once constructed.
  
  Examples
  --------
  >>> import numpy as np
  >>> from scipy.sparse import dok_matrix
  >>> S = dok_matrix((5, 5), dtype=np.float32)
  >>> for i in range(5):
  ...     for j in range(5):
  ...         S[i, j] = i + j    # Update element
class_docstr_tok: ["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'","Attributes","--","--","--","--","--","dtype",":","dtype","Data","type","of","the","matrix","shape",":","2-tuple","Shape","of","the","matrix","ndim",":","int","Number","of","dimensions","(","this","is","always","2",")","nnz","Number","of","nonzero","elements","Notes","--","--","-","Sparse","matrices","can","be","used","in","arithmetic","operations",":","they","support","addition",",","subtraction",",","multiplication",",","division",",","and","matrix","power",".","Allows","for","efficient","O","(","1",")","access","of","individual","elements",".","Duplicates","are","not","allowed",".","Can","be","efficiently","converted","to","a","coo_matrix","once","constructed",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","scipy.sparse","import","dok_matrix",">",">",">","S","=","dok_matrix","(","(","5",",","5",")",",","dtype=np.float32",")",">",">",">","for","i","in","range","(","5",")",":","...","for","j","in","range","(","5",")",":","...","S","[","i",",","j","]","=","i","+","j","#","Update","element"]
code: def __setitem__(self, index, x):
      if isinstance(index, tuple) and len(index) == 2:
          # Integer index fast path
          i, j = index
          if (
              isintlike(i)
              and isintlike(j)
              and 0 <= i < self.shape[0]
              and 0 <= j < self.shape[1]
          ):
              v = np.asarray(x, dtype=self.dtype)
              if v.ndim == 0 and v != 0:
                  dict.__setitem__(self, (int(i), int(j)), v[()])
                  return
  
      i, j = self._unpack_index(index)
      i, j = self._index_to_arrays(i, j)
  
      if isspmatrix(x):
          x = x.toarray()
  
      # Make x and i into the same shape
      x = np.asarray(x, dtype=self.dtype)
      x, _ = np.broadcast_arrays(x, i)
  
      if x.shape != i.shape:
          raise ValueError("Shape mismatch in assignment.")
  
      if np.size(x) == 0:
          return
  
      min_i = i.min()
      if min_i < -self.shape[0] or i.max() >= self.shape[0]:
          raise IndexError(
              "Index (%d) out of range -%d to %d."
              % (i.min(), self.shape[0], self.shape[0] - 1)
          )
      if min_i < 0:
          i = i.copy()
          i[i < 0] += self.shape[0]
  
      min_j = j.min()
      if min_j < -self.shape[1] or j.max() >= self.shape[1]:
          raise IndexError(
              "Index (%d) out of range -%d to %d."
              % (j.min(), self.shape[1], self.shape[1] - 1)
          )
      if min_j < 0:
          j = j.copy()
          j[j < 0] += self.shape[1]
  
      dict.update(self, izip(izip(i.flat, j.flat), x.flat))
  
      if 0 in x:
          zeroes = x == 0
          for key in izip(i[zeroes].flat, j[zeroes].flat):
              if dict.__getitem__(self, key) == 0:
                  # may have been superseded by later update
                  del self[key]
  
imports: from __future__ import division, print_function, absolute_import
  import functools
  import operator
  import itertools
  import numpy
  from scipy._lib.six import zip, xrange, iteritems, iterkeys, itervalues
  from .base import spmatrix, isspmatrix
  from .sputils import isdense, getdtype, isshape, isintlike, isscalarlike, upcast, upcast_scalar, IndexMixin, get_index_dtype, check_shape
label_desc: Use image node_id 11 for calling the dok_matrix obj's underlying member method code with example usage: obj.__setitem__(index, x) without return types