In [1]:
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix

In [2]:
lil = lil_matrix((3, 3), dtype=int)
print(lil.toarray())


[[0 0 0]
 [0 0 0]
 [0 0 0]]

In [3]:
lil[1, 0] = 10
lil[2, 2] = 30

In [4]:
print(lil)


  (1, 0)	10
  (2, 2)	30

In [5]:
print(lil.toarray())


[[ 0  0  0]
 [10  0  0]
 [ 0  0 30]]

In [6]:
lil[2, 2] = 0

In [7]:
print(lil)


  (1, 0)	10

In [8]:
print(lil.toarray())


[[ 0  0  0]
 [10  0  0]
 [ 0  0  0]]

In [9]:
csr = csr_matrix((3, 3), dtype=int)
print(csr.toarray())


[[0 0 0]
 [0 0 0]
 [0 0 0]]

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