'Converts MutableDenseNDimArray to Matrix. Can convert only 2-dim array, else will raise error.
Examples
>>> from sympy import MutableDenseNDimArray
>>> a = MutableDenseNDimArray([1 for i in range(9)], (3, 3))
>>> b = a.tomatrix()
>>> b
Matrix([
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])'

def tomatrix(self):

    from sympy.matrices import Matrix
    if (self.rank() != 2):
        raise ValueError('Dimensions    must    be    of    size    of    2')
    return Matrix(self.shape[0], self.shape[1], self._array)
