for i in range(a.shape[0]):
    if x.data[i]:
        for j in range(len(x.data[i])):
            x.data[i] *= b[x.rows[i]]
return x
How to elementwise-multiply a scipy.sparse matrix by a broadcasted dense 1d array?