Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?


1 Answers

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

like image 182
honza_p Avatar answered Aug 08 '26 07:08

honza_p



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!