def check_2d(inp):
if isinstance(inp, list):<EOL><INDENT>return check_2d(np.array(inp))<EOL><DEDENT>if isinstance(inp, (np.ndarray, np.matrixlib.defmatrix.matrix)):<EOL><INDENT>if inp.ndim == <NUM_LIT:2>: <EOL><INDENT>return inp<EOL><DEDENT><DEDENT>if sps.issparse(inp):<EOL><INDENT>if inp.ndim == <NUM_LIT:2>: <EOL><INDENT>return inp<EOL><DEDENT><DEDENT>
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