code: def check_2d(inp):
      
      if isinstance(inp, list):
          return check_2d(np.array(inp))
      if isinstance(inp, (np.ndarray, np.matrixlib.defmatrix.matrix)):
          if inp.ndim == 2: # input is a dense matrix
              return inp
      if sps.issparse(inp):
          if inp.ndim == 2: # input is a sparse matrix
              return inp
docs: Check input to be a matrix. Converts lists of lists to np.ndarray.
  
      Also allows the input to be a scipy sparse matrix.
      
      Parameters
      ----------
      inp : obj
          Input matrix
  
      Returns
      -------
      numpy.ndarray, scipy.sparse or None
          Input matrix or None
  
      Examples
      --------
      >>> check_2d([[0, 1], [2, 3]])
      [[0, 1], [2, 3]]
  
      >>> check_2d('test')
      None