(self, other)
return M
Add two sparse matrices with dictionary representation.

        Examples
        ========

        >>> from sympy.matrices import SparseMatrix, eye, ones
        >>> SparseMatrix(eye(3)).add(SparseMatrix(ones(3)))
        Matrix([
        [2, 1, 1],
        [1, 2, 1],
        [1, 1, 2]])
        >>> SparseMatrix(eye(3)).add(-SparseMatrix(eye(3)))
        Matrix([
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])

        Only the non-zero elements are stored, so the resulting dictionary
        that is used to represent the sparse matrix is empty:
        >>> _._smat
        {}

        See Also
        ========

        multiply
Add two sparse matrices with dictionary representation.
Add two sparse matrices with dictionary representation .
def add(self, other):
        """Add two sparse matrices with dictionary representation.

        Examples
        ========

        >>> from sympy.matrices import SparseMatrix, eye, ones
        >>> SparseMatrix(eye(3)).add(SparseMatrix(ones(3)))
        Matrix([
        [2, 1, 1],
        [1, 2, 1],
        [1, 1, 2]])
        >>> SparseMatrix(eye(3)).add(-SparseMatrix(eye(3)))
        Matrix([
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])

        Only the non-zero elements are stored, so the resulting dictionary
        that is used to represent the sparse matrix is empty:
        >>> _._smat
        {}

        See Also
        ========

        multiply
        """
        if not isinstance(other, SparseMatrix):
            raise ValueError('only use add with %s, not %s' %
                tuple([c.__class__.__name__ for c in (self, other)]))
        if self.shape != other.shape:
            raise ShapeError()
        M = self.copy()
        for i, v in other._smat.items():
            v = M[i] + v
            if v:
                M._smat[i] = v
            else:
                M._smat.pop(i, None)
        return M
def add ( self , other ) : if not isinstance ( other , SparseMatrix ) : raise ValueError ( 'only use add with %s, not %s' % tuple ( [ c . __class__ . __name__ for c in ( self , other ) ] ) ) if self . shape != other . shape : raise ShapeError ( ) M = self . copy ( ) for i , v in other . _smat . items ( ) : v = M [ i ] + v if v : M . _smat [ i ] = v else : M . _smat . pop ( i , None ) return M