def sparse_max_row(csr_mat):
    ret = np.maximum.reduceat(csr_mat.data, csr_mat.indptr[:-1])
ret[np.diff(csr_mat.indptr) == 0] = 0
return ret
efficient way to get the max of each row for large sparse matrix