Search code examples
pythonscipysparse-matrix

Python - mapping over a sparse matrix


I am working with a csr_matrix (from scipy.sparse) and I need to apply a logarithm-like function on all its items.

f:x->log(x+1), so f(0)=0).

What would be the efficient way of doing that ?

I could not found any map function for csr_matrix, do I have forgotten one ?


Solution

  • What about (specifically for this function) log1p?

    See the scipy documentation: http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.log1p.html