Created
February 6, 2013 18:00
-
-
Save anonymous/4724485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
343 def sparsify(m, value=100): | |
344 | |
345 matrix = m.tolil() | |
346 rows, columns = matrix.shape | |
347 sparseindex = matrix.mean(axis=1) * (value/float(100)) | |
348 for r in range(rows): | |
349 z = np.where(matrix.tocsr()[r].todense() < sparseindex[r])[1] | |
350 for c in range(z.shape[1]): | |
351 var = int(z[0,c]) | |
352 matrix[r, var] = 0 | |
353 | |
354 return matrix.tocsr() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment