netrd/utilities/threshold.py
def threshold_on_degree(mat, avg_k=1):
    """
    Threshold a numpy array by setting values below a given quantile to zero.

    Params
    ------
    mat: (np.ndarray): A numpy array.
    avg_k (float): The average degree to target when thresholding the matrix.

    Returns
    -------
    thresholded_mat: the thresholded numpy array

    """

    n = len(mat)
    A = np.ones((n, n))

    for m in sorted(mat.flatten()):
        A[mat == m] = 0
        if np.mean(np.sum(A, 1)) <= avg_k:
            break

    return mat * (mat >= m)

    Threshold a numpy array by setting values below a given quantile to zero.

    Params
    ------
    mat: (np.ndarray): A numpy array.
    avg_k (float): The average degree to target when thresholding the matrix.

    Returns
    -------
    thresholded_mat: the thresholded numpy array

    
Threshold a numpy array by setting values below a given quantile to zero.
Params



Returns

the thresholded numpy array
Threshold a numpy array by setting values below a given quantile to zero . Params Returns the thresholded numpy array
def threshold_on_degree(mat, avg_k=1):
    n = len(mat)
    A = np.ones((n, n))
    for m in sorted(mat.flatten()):
        A[mat == m] = 0
        if np.mean(np.sum(A, 1)) <= avg_k:
            break
    return mat * (mat >= m)
def threshold_on_degree ( mat , avg_k = 1 ) : n = len ( mat ) A = np . ones ( ( n , n ) ) for m in sorted ( mat . flatten ( ) ) : A [ mat == m ] = 0 if np . mean ( np . sum ( A , 1 ) ) <= avg_k : break return mat * ( mat >= m )
Threshold a numpy array by setting values below a given quantile to zero.
Threshold a numpy array by setting values below a given quantile to zero .
"""
    Threshold a numpy array by setting values below a given quantile to zero.

    Params
    ------
    mat: (np.ndarray): A numpy array.
    avg_k (float): The average degree to target when thresholding the matrix.

    Returns
    -------
    thresholded_mat: the thresholded numpy array

    """
mat
avg_k