def normalize(matrix):
'''Normalize each row (L2-norm) of a CSR sparse matrix (it should work with most sparse matrices though)'''
sparsy = matrix.tocoo()
data = [float(d) for d in sparsy.data]
return Normalizer().transform(csr_matrix((data, (sparsy.row, sparsy.col))))
#
# Simple tests
#
评论列表
文章目录