'Apply a function to each element of the matrix.
Examples
>>> from sympy.matrices import SparseMatrix
>>> m = SparseMatrix(2, 2, lambda i, j: i*2+j)
>>> m
Matrix([
[0, 1],
[2, 3]])
>>> m.applyfunc(lambda i: 2*i)
Matrix([
[0, 2],
[4, 6]])'

def applyfunc(self, f):

    if (not callable(f)):
        raise TypeError('`f`    must    be    callable.')
    out = self.copy()
    for (k, v) in self._smat.items():
        fv = f(v)
        if fv:
            out._smat[k] = fv
        else:
            out._smat.pop(k, None)
    return out
