In [1]:
from scipy.sparse import csr_matrix, csc_matrix, coo_matrix, lil_matrix
In [2]:
l = [[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]]
In [3]:
csr = csr_matrix(l)
csc = csc_matrix(l)
coo = coo_matrix(l)
lil = lil_matrix(l)
In [4]:
print(csr.getrow(0))
In [5]:
print(type(csr.getrow(0)))
In [6]:
print(csr.getrow(0).shape)
In [7]:
print(csr.getrow(0).toarray())
In [8]:
print(type(csc.getrow(0)))
In [9]:
print(type(coo.getrow(0)))
In [10]:
print(type(lil.getrow(0)))
In [11]:
print(csr.getcol(0))
In [12]:
print(type(csr.getcol(0)))
In [13]:
print(csr.getcol(0).shape)
In [14]:
print(csr.getcol(0).toarray())
In [15]:
print(type(csc.getcol(0)))
In [16]:
print(type(coo.getcol(0)))
In [17]:
print(type(lil.getcol(0)))
In [18]:
lil_row = lil.getrow(0)
In [19]:
lil_row[0, 0] = 100
In [20]:
print(lil.toarray())
In [21]:
print(lil_row.toarray())