Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pointwise operations on scipy.sparse matrices

Is it possible to apply for example numpy.exp or similar pointwise operators to all elements in a scipy.sparse.lil_matrix or another sparse matrix format?

import numpy
from scipy.sparse import lil_matrix

x = numpy.ones((10,10))
y = numpy.exp(x)

x = lil_matrix(numpy.ones((10,10)))
# y = ????

numpy.exp(x) or scipy.exp(x) yields an AttributeError, and numpy.exp(x.data) yields the same.

thanks!

like image 885
hannes Avatar asked Mar 25 '11 10:03

hannes


1 Answers

I do not know the full details, but converting to another type works, at least when using the array of non zero elements:

xcsc = x.tocsc()
numpy.exp(xcsc.data) # works
like image 123
Olivier Verdier Avatar answered Nov 06 '22 23:11

Olivier Verdier