(
    doc_term_matrix: sp.csr_matrix,
    *,
    type_: Literal["linear", "sqrt", "log"] = "linear",
)
Compute frequencies for all terms in a document-term matrix, with optional
    sub-linear scaling.

    Args:
        doc_term_matrix: M x N sparse matrix, where M is the # of docs and
            N is the # of unique terms. Values must be the linear, un-scaled counts
            of term n per doc m.
        type_: Scaling applied to absolute term counts.
            If 'linear', term counts are left as-is, since the sums are already
            linear; if 'sqrt', tf => sqrt(tf); if 'log', tf => log(tf) + 1.

    Returns:
        Array of term frequencies, with length equal to the # of unique terms
        (i.e. # of columns) in ``doc_term_matrix``.

    Raises:
        ValueError: if ``doc_term_matrix`` doesn't have any non-zero entries, or
            if ``type_`` isn't one of {"linear", "sqrt", "log"}.
Compute frequencies for all terms in a document-term matrix, with optional
    sub-linear scaling.
Compute frequencies for all terms in a document - term matrix with optional sub - linear scaling .
def get_term_freqs(
    doc_term_matrix: sp.csr_matrix,
    *,
    type_: Literal["linear", "sqrt", "log"] = "linear",
) -> np.ndarray:
    """
    Compute frequencies for all terms in a document-term matrix, with optional
    sub-linear scaling.

    Args:
        doc_term_matrix: M x N sparse matrix, where M is the # of docs and
            N is the # of unique terms. Values must be the linear, un-scaled counts
            of term n per doc m.
        type_: Scaling applied to absolute term counts.
            If 'linear', term counts are left as-is, since the sums are already
            linear; if 'sqrt', tf => sqrt(tf); if 'log', tf => log(tf) + 1.

    Returns:
        Array of term frequencies, with length equal to the # of unique terms
        (i.e. # of columns) in ``doc_term_matrix``.

    Raises:
        ValueError: if ``doc_term_matrix`` doesn't have any non-zero entries, or
            if ``type_`` isn't one of {"linear", "sqrt", "log"}.
    """
    if doc_term_matrix.nnz == 0:
        raise ValueError("`doc_term_matrix` must have at least 1 non-zero entry")
    tfs = np.asarray(doc_term_matrix.sum(axis=0)).ravel()
    if type_ == "linear":
        return tfs  # tfs is already linear
    elif type_ == "sqrt":
        return np.sqrt(tfs)
    elif type_ == "log":
        return np.log(tfs) + 1.0
    else:
        raise ValueError(
            errors.value_invalid_msg("type_", type_, {"linear", "sqrt", "log"})
        )
def get_term_freqs ( doc_term_matrix : sp . csr_matrix , * , type_ : Literal [ "linear" , "sqrt" , "log" ] = "linear" , ) -> np . ndarray : if doc_term_matrix . nnz == 0 : raise ValueError ( "`doc_term_matrix` must have at least 1 non-zero entry" ) tfs = np . asarray ( doc_term_matrix . sum ( axis = 0 ) ) . ravel ( ) if type_ == "linear" : return tfs # tfs is already linear elif type_ == "sqrt" : return np . sqrt ( tfs ) elif type_ == "log" : return np . log ( tfs ) + 1.0 else : raise ValueError ( errors . value_invalid_msg ( "type_" , type_ , { "linear" , "sqrt" , "log" } ) )