def sum(X, v):
    rows, cols = X.shape
row_start_stop = as_strided(X.indptr, shape=(rows, 2), strides=2 * X.indptr
    .strides)
for row, (start, stop) in enumerate(row_start_stop):
    data = X.data[start:stop]
data -= v[row]
sum(mat, vec.A)
print(mat.A)
Efficiently Subtract Vector from Matrix (Scipy)