[PYTHON] Nehmen Sie die logarithmische Darstellung von Nicht-Null-Elementen in scipy.sparse

Ich fand nicht viel, selbst als ich es nachschlug, also machte ich mir eine Notiz.

Referenz: http://stackoverflow.com/questions/6256206/scipy-sparse-default-value

Der Punkt ist, dass Sie es nicht mit lil machen können, aber Sie können es mit coo, csr, csc machen.

>>> import numpy as np
>>> from scipy.sparse import lil_matrix
>>> a = lil_matrix((3,2))
>>> a[0,0] = 10
>>> a[0,1] = 3
>>> a[1,0] = 11
>>> a[1,1] = 100
>>> a[2,0] = 12
>>> a.todense()
matrix([[  10.,    3.],
        [  11.,  100.],
        [  12.,    0.]])
>>> b = a.tocsr()
>>> a.data
array([[10.0, 3.0], [11.0, 100.0], [12.0]], dtype=object)
>>> np.log(a.data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'log'
>>> b.data
array([  10.,    3.,   11.,  100.,   12.])
>>> np.log(b.data)
array([ 2.30258509,  1.09861229,  2.39789527,  4.60517019,  2.48490665])
>>> b.data = np.log(b.data)
>>> b.todense()
matrix([[ 2.30258509,  1.09861229],
        [ 2.39789527,  4.60517019],
        [ 2.48490665,  0.        ]])

Recommended Posts

Nehmen Sie die logarithmische Darstellung von Nicht-Null-Elementen in scipy.sparse
Nimm das Ausführungsprotokoll von Sellerie
Holen Sie sich das erste Element von Queryset
Werfen Sie einen Blick auf die Verarbeitung von LightGBM Tuner
Machen Sie LCD-Screenshots mit Python-LEGO Mindstorms
Nehmen Sie den Wert des SwitchBot-Thermo-Hygrometers mit Raspberry Pi
Der Beginn von cif2cell
der Zen von Python
Die Geschichte von sys.path.append ()
Rache der Typen: Rache der Typen
Ermitteln Sie die Anzahl der Vorkommen für jedes Element in der Liste
Ruft den Index jedes Elements der Verwirrungsmatrix in Python ab