Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some confusion in pecos.utils.smat_utils.binarized #265

Open
denghj3 opened this issue Nov 22, 2023 · 1 comment
Open

Some confusion in pecos.utils.smat_utils.binarized #265

denghj3 opened this issue Nov 22, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@denghj3
Copy link

denghj3 commented Nov 22, 2023

Description

the func show below, it describe all nonzero elements become 1, while it change the the whole mat to 1 in reality, with using X.data[:] = 1 or X[:] = 1

def binarized(X, inplace=False):
    """Binarize a dense/sparse matrix. All nonzero elements become 1.

    Args:
        X (np.ndarray, spmatrix): input matrix to binarize
        inplace (bool, optional): if True do the binarization in-place, else return a copy. Default False

    Returns:
        binarized X
    """

    if not isinstance(X, (np.ndarray, smat.spmatrix)):
        raise NotImplementedError(
            "this function only support X being np.ndarray or scipy.sparse.spmatrix."
        )

    if not inplace:
        X = X.copy()

    if isinstance(X, smat.spmatrix):
        X.data[:] = 1
    else:
        X[:] = 1

    return X

References

  • list reference and related literature
  • list known implementations
@denghj3 denghj3 added the enhancement New feature or request label Nov 22, 2023
@denghj3
Copy link
Author

denghj3 commented Nov 29, 2023

i have some ideas: when the X is spmatrix, it is right. But when the X is np.ndarray, it will change the whole ndarray to 1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant