(self, other)
Return self + other, raising ShapeError if shapes don't match.
Return self + other, raising ShapeError if shapes don't match.
Return self + other raising ShapeError if shapes don t match .
def __add__(self, other):
        """Return self + other, raising ShapeError if shapes don't match."""
        if getattr(other, 'is_Matrix', False):
            A = self
            B = other
            if A.shape != B.shape:
                raise ShapeError("Matrix size mismatch.")
            alst = A.tolist()
            blst = B.tolist()
            ret = [S.Zero]*A.rows
            for i in range(A.shape[0]):
                ret[i] = list(map(lambda j, k: j + k, alst[i], blst[i]))
            rv = classof(A, B)._new(ret)
            if 0 in A.shape:
                rv = rv.reshape(*A.shape)
            return rv
        raise TypeError('cannot add matrix and %s' % type(other))
def __add__ ( self , other ) : if getattr ( other , 'is_Matrix' , False ) : A = self B = other if A . shape != B . shape : raise ShapeError ( "Matrix size mismatch." ) alst = A . tolist ( ) blst = B . tolist ( ) ret = [ S . Zero ] * A . rows for i in range ( A . shape [ 0 ] ) : ret [ i ] = list ( map ( lambda j , k : j + k , alst [ i ] , blst [ i ] ) ) rv = classof ( A , B ) . _new ( ret ) if 0 in A . shape : rv = rv . reshape ( * A . shape ) return rv raise TypeError ( 'cannot add matrix and %s' % type ( other ) )