In [1]:
import numpy as np
from scipy.sparse import csr_matrix, lil_matrix
In [2]:
l = [[0, 1, 2],
[3, 0, 4],
[0, 0, 0]]
In [3]:
csr = csr_matrix(l)
lil = lil_matrix(l)
In [4]:
print(csr.sum())
In [5]:
print(csr.mean())
In [6]:
print(csr.max())
In [7]:
print(csr.min())
In [8]:
# print(lil.max())
# AttributeError: max not found
In [9]:
print(csr.sqrt().toarray())
In [10]:
print(csr.sin().toarray())
In [11]:
print(csr.tan().toarray())
In [12]:
# print(lil.sqrt())
# AttributeError: sqrt not found
In [13]:
csr_ = csr.copy()
In [14]:
print(csr_.data)
In [15]:
print(type(csr_.data))
In [16]:
csr_.data = np.cos(csr_.data)
In [17]:
print(csr_.toarray())
In [18]:
csr_ = csr.copy()
csr_.data = csr_.data ** 2
print(csr_.toarray())
In [19]:
print(lil.data)
In [20]:
print(csr)
In [21]:
r, c = csr.nonzero()
print(r, c)
In [22]:
print(csr.count_nonzero())
In [23]:
print(csr.nnz)
In [24]:
csr[0, 1] = 0
print(csr)
In [25]:
print(csr.count_nonzero())
In [26]:
print(csr.nnz)
In [27]:
r, c = csr.nonzero()
print(r, c)
In [28]:
print(lil)
In [29]:
print(lil.nnz)
In [30]:
lil[0, 1] = 0
In [31]:
print(lil)
In [32]:
print(lil.nnz)