def denseToSparseAbvCutoff(self, denseMatrix, cutoff):
"""
Remove datas in denseMatrix that is below cutoff, Convert the remaining datas into sparse matrix.
Parameters:
----------------------
denseMatrix: dense numpy matrix
cutoff: int or float
Returns
----------------------
Scipy csr_matrix
"""
maskArray=denseMatrix>=cutoff
sparseMatrix=csr_matrix( (np.asarray(denseMatrix[maskArray]).reshape(-1),np.nonzero(maskArray)),\
shape=denseMatrix.shape)
return sparseMatrix
评论列表
文章目录