``````

In [1]:

from scipy.sparse import csr_matrix, csc_matrix, coo_matrix, lil_matrix

``````
``````

In [2]:

l = [[0, 10, 20],
[30, 0, 40],
[0, 0, 50]]

``````
``````

In [3]:

data = [10, 20, 30, 40, 50]
row = [0, 0, 1, 1, 2]
col = [1, 2, 0, 2, 2]

``````
``````

In [4]:

csr = csr_matrix(l)
print(csr)

``````
``````

(0, 1)	10
(0, 2)	20
(1, 0)	30
(1, 2)	40
(2, 2)	50

``````
``````

In [5]:

print(type(csr))

``````
``````

<class 'scipy.sparse.csr.csr_matrix'>

``````
``````

In [6]:

print(csr.data)

``````
``````

[10 20 30 40 50]

``````
``````

In [7]:

print(csr.indices)

``````
``````

[1 2 0 2 2]

``````
``````

In [8]:

print(csr.indptr)

``````
``````

[0 2 4 5]

``````
``````

In [9]:

csc = csc_matrix(l)
print(csc)

``````
``````

(1, 0)	30
(0, 1)	10
(0, 2)	20
(1, 2)	40
(2, 2)	50

``````
``````

In [10]:

print(type(csc))

``````
``````

<class 'scipy.sparse.csc.csc_matrix'>

``````
``````

In [11]:

print(csc.data)

``````
``````

[30 10 20 40 50]

``````
``````

In [12]:

print(csc.indices)

``````
``````

[1 0 0 1 2]

``````
``````

In [13]:

print(csc.indptr)

``````
``````

[0 1 2 5]

``````
``````

In [14]:

coo = coo_matrix(l)
print(coo)

``````
``````

(0, 1)	10
(0, 2)	20
(1, 0)	30
(1, 2)	40
(2, 2)	50

``````
``````

In [15]:

print(type(coo))

``````
``````

<class 'scipy.sparse.coo.coo_matrix'>

``````
``````

In [16]:

print(coo.data)

``````
``````

[10 20 30 40 50]

``````
``````

In [17]:

print(coo.row)

``````
``````

[0 0 1 1 2]

``````
``````

In [18]:

print(coo.col)

``````
``````

[1 2 0 2 2]

``````
``````

In [19]:

lil = lil_matrix(l)
print(lil)

``````
``````

(0, 1)	10
(0, 2)	20
(1, 0)	30
(1, 2)	40
(2, 2)	50

``````
``````

In [20]:

print(type(lil))

``````
``````

<class 'scipy.sparse.lil.lil_matrix'>

``````
``````

In [21]:

print(lil.data)

``````
``````

[list([10, 20]) list([30, 40]) list([50])]

``````
``````

In [22]:

print(lil.rows)

``````
``````

[list([1, 2]) list([0, 2]) list([2])]

``````