def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,<EOL>force_all_finite=True, ensure_2d=True, allow_nd=False):
if isinstance(accept_sparse, str):<EOL><INDENT>accept_sparse = [accept_sparse]<EOL><DEDENT>if sp.issparse(array):<EOL><INDENT>array = _ensure_sparse_format(array, accept_sparse, dtype, order,<EOL>copy, force_all_finite)<EOL><DEDENT>else:<EOL><INDENT>if ensure_2d:<EOL><INDENT>array = np.atleast_2d(array)<EOL><DEDENT>array = np.array(array, dtype=dtype, order=order, copy=copy)<EOL>if not allow_nd and array.ndim >= <NUM_LIT:3>:<EOL><INDENT>raise ValueError("<STR_LIT>" %<EOL>array.ndim)<EOL><DEDENT>if force_all_finite:<EOL><INDENT>_assert_all_finite(array)<EOL><DEDENT><DEDENT>return array<EOL>
Input validation on an array, list, sparse matrix or similar.

    By default, the input is converted to an at least 2nd numpy array.

    Parameters
    ----------
    array : object
        Input object to check / convert.

    accept_sparse : string, list of string or None (default=None)
        String[s] representing allowed sparse matrix formats, such as 'csc',
        'csr', etc.  None means that sparse matrix input will raise an error.
        If the input is sparse but not in the allowed format, it will be
        converted to the first listed format.

    order : 'F', 'C' or None (default=None)
        Whether an array will be forced to be fortran or c-style.

    copy : boolean (default=False)
        Whether a forced copy will be triggered. If copy=False, a copy might
        be triggered by a conversion.

    force_all_finite : boolean (default=True)
        Whether to raise an error on np.inf and np.nan in X.

    ensure_2d : boolean (default=True)
        Whether to make X at least 2d.

    allow_nd : boolean (default=False)
        Whether to allow X.ndim > 2.

    Returns
    -------
    X_converted : object
        The converted and validated X.