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
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
References