How to elementwise-multiply a scipy.sparse matrix by a broadcasted dense 1d array?
Suppose I have a 2d sparse array. In my real usecase both the number of rows and columns are much bigger (say 20000 and 50000) hence it cannot fit in memory when a dense representation is used: >>> import numpy as np >>> import scipy.sparse as ssp >>> a = ssp.lil_matrix((5, 3)) >>> a[1, 2] = -1 >>> a[4, 1] = 2 >>> a.todense() matrix([[ 0., 0., 0.], [ 0., 0., -1.], [ 0., 0., 0.], [ 0., 0., 0.], [ 0., 2., 0.]]) Now suppose I have a dense 1d array with all non-zeros components with size 3 (or 50000 in my real life case): >>> d = np.ones(3) * 3 >>> d array([ 3., 3., 3.]) I would like to compute