I have an numpy array V
with a shape of (1, 1000)
. I also have a csr_matrix M
with a shape of (100000, 1000)
. For every row m
in M
, I want to compute the pairwise minimum between V
and m
, and store all the results in a new matrix, and I want to do it efficiently. The final result should also be a matrix with a shape of (100000, 1000)
.
Some approaches that I considered/tried:
- Iterate over each row of
M
with a for loop. This works, but it is quite slow. - Convert
M
to a matrix:numpy.minimum(V, M.toarray())
which takes a huge amount of memory. numpy.minimum(V, M)
does not work. I get an error which says:Comparing a sparse matrix with a scalar less than zero using >= is inefficient
.
What would be a good and efficient way to do this without taking too much memory or time?