In [1]:
import numpy as np
from scipy.sparse import csr_matrix

In [2]:
l = [[0, 10, 20],
     [30, 0, 40],
     [0, 0, 0]]

In [3]:
csr = csr_matrix(l)
print(csr)


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

In [4]:
print(type(csr))


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

In [5]:
print(csr.shape)


(3, 3)

In [6]:
a = np.array(l)
print(a)


[[ 0 10 20]
 [30  0 40]
 [ 0  0  0]]

In [7]:
print(type(a))


<class 'numpy.ndarray'>

In [8]:
csr = csr_matrix(a)
print(csr)


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

In [9]:
print(type(csr))


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

In [10]:
print(csr_matrix([0, 1, 2]))


  (0, 1)	1
  (0, 2)	2

In [11]:
print(csr_matrix([0, 1, 2]).shape)


(1, 3)

In [12]:
# print(csr_matrix([[[0, 1, 2]]]))
# TypeError: expected dimension <= 2 array or matrix

In [13]:
print(csr.toarray())


[[ 0 10 20]
 [30  0 40]
 [ 0  0  0]]

In [14]:
print(type(csr.toarray()))


<class 'numpy.ndarray'>

In [15]:
print(csr.toarray().tolist())


[[0, 10, 20], [30, 0, 40], [0, 0, 0]]

In [16]:
print(type(csr.toarray().tolist()))


<class 'list'>

In [17]:
print(csr.todense())


[[ 0 10 20]
 [30  0 40]
 [ 0  0  0]]

In [18]:
print(type(csr.todense()))


<class 'numpy.matrix'>