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