docstr: 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]])
docstr_tok: ["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","]","]",")"]
code: def tomatrix(self):
      """
      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]])
  
      """
      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)
  
imports: import functools
  from typing import List
  from sympy.core.basic import Basic
  from sympy.core.containers import Tuple
  from sympy.core.singleton import S
  from sympy.core.sympify import _sympify
  from sympy.tensor.array.mutable_ndim_array import MutableNDimArray
  from sympy.tensor.array.ndim_array import NDimArray, ImmutableNDimArray, ArrayKind
  from sympy.utilities.iterables import flatten
label_desc: Use image node_id 5 for calling the DenseNDimArray obj's underlying member method code with example usage: obj.tomatrix() and returns: Matrix