def csr_add_sparse_vec(sps_mat, sps_vec):
    """Adds a sparse vector to every row of a sparse matrix"""
rows, cols = sps_mat.shape
new_data = sps_mat.data
new_pointer = sps_mat.indptr.copy()
new_cols = sps_mat.indices
aux_idx = np.arange(rows + 1)
for value, col in zip(sps_vec.data, sps_vec.indices):
    new_data = np.insert(new_data, new_pointer[1:], [value] * rows)
new_cols = np.insert(new_cols, new_pointer[1:], [col] * rows)
new_pointer += aux_idx
return sps.csr_matrix((new_data, new_cols, new_pointer), shape=sps_mat.shape)
Adding a very repetitive matrix to a sparse one in numpy/scipy?