How to raise the scipy.sparse matrix to the level of power, by elements? numpy.power should, according to his manual , do this, but it does not work on sparse matrices:
>>> X <1353x32100 sparse matrix of type '<type 'numpy.float64'>' with 144875 stored elements in Compressed Sparse Row format> >>> np.power(X, 2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../scipy/sparse/base.py", line 347, in __pow__ raise TypeError('matrix is not square') TypeError: matrix is not square
Same problem with X**2 . Converting to a dense array works, but spends precious seconds.
I had the same problem with np.multiply , which I decided to use using the multiply sparse matrix method, but there seems to be no pow method.
source share