In [1]:
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
In [2]:
lil = lil_matrix((3, 3), dtype=int)
print(lil.toarray())
In [3]:
lil[1, 0] = 10
lil[2, 2] = 30
In [4]:
print(lil)
In [5]:
print(lil.toarray())
In [6]:
lil[2, 2] = 0
In [7]:
print(lil)
In [8]:
print(lil.toarray())
In [9]:
csr = csr_matrix((3, 3), dtype=int)
print(csr.toarray())
In [10]:
# csr[1, 0] = 10
# SparseEfficiencyWarning: Changing the sparsity structure of a csr_matrix is expensive. lil_matrix is more efficient.
In [11]:
coo = coo_matrix((3, 3), dtype=int)
In [12]:
# coo[1, 0] = 10
# TypeError: 'coo_matrix' object does not support item assignment