2016-10-03 11 views
0

Ich habe eine scipy.sparse.csc.csc_matrix. Ich möchte für jedes Element dieser Matrix eine Potenzfunktion verwenden, so dass jedes Element auf die Potenz erhöht wird. Wie soll ich das machen?Scipy Sparse-Matrix auf die Power-Ersatz-Matrix

Ich versuchte dies:

B.data ** B.data 

Aber diese entfernt 0 aus den Daten

Antwort

1

Ich habe keine Probleme mit diesem Ansatz:

In [155]: B=sparse.random(10,10,.1,'csc') 
In [156]: B 
Out[156]: 
<10x10 sparse matrix of type '<class 'numpy.float64'>' 
    with 10 stored elements in Compressed Sparse Column format> 
In [157]: B.data 
Out[157]: 
array([ 0.79437782, 0.74414493, 0.3922551 , 0.61980213, 0.45231045, 
     0.94498933, 0.53086532, 0.54611246, 0.52941419, 0.81069106]) 
In [158]: B.data=B.data**B.data 
In [159]: B.data 
Out[159]: 
array([ 0.83288253, 0.80259158, 0.69274789, 0.74342645, 0.69847422, 
     0.94793528, 0.71450246, 0.71866496, 0.71412372, 0.84354814]) 
In [160]: B 
Out[160]: 
<10x10 sparse matrix of type '<class 'numpy.float64'>' 
    with 10 stored elements in Compressed Sparse Column format>