I have a csr sparse scipy matrix X
which is order (10^4, 10^7) elements, and a numpy array r
with 10^7 elements. I need to multiply each column of the X
matrix by the corresponding element of r
, i.e., I need:
X_new[:,i] = X[:,i] * r[i]
In theory is this done by using X.multiply(r)
, but the multiply method tries to make X
dense and this gives a MemoryError. Doing
for i in range(len(r)):
X_new[:,i] = X[:,i] * r[i]
Takes impossibly long. I would like to know if anyone has any idea how to do this.