'Return a new matrix with xreplace applied to each entry.
Examples
>>> from sympy.abc import x, y
>>> from sympy.matrices import SparseMatrix, Matrix
>>> SparseMatrix(1, 1, [x])
Matrix([[x]])
>>> _.xreplace({x: y})
Matrix([[y]])
>>> Matrix(_).xreplace({y: x})
Matrix([[x]])'

def xreplace(self, rule):

    return self.applyfunc((lambda x: x.xreplace(rule)))
