In [5]:
import scipy.sparse
from scipy import array

In [3]:
scipy.sparse.csr_matrix?

In [15]:
indptr = array([0,2,3,6])
# this says that, in indices,
#                |--| go in row 1 
#                     |-| go in row 2
#                         |-----| go in row 3
# indptr could also be expressed as something like:
#                0  0  1  2  2  2
indices = array([0, 2, 2, 0, 1, 2])
data = array([1,2,3,4,5,6])
mat = scipy.sparse.csr_matrix((data, indices, indptr), shape=(3,3) )
# column indices for row i are stored in indices[indptr[i]:indptr[i+1]]
for row_i in range(3):
    print 'row_i', row_i, 'col_index', indices[indptr[row_i]:indptr[row_i+1]], '(', indptr[row_i], '..', indptr[row_i+1], ')'
# and their corresponding values are stored in data[indptr[i]:indptr[i+1]].
# If the shape parameter is not supplied, the matrix dimensions are inferred from the index arrays.


row_i 0 col_index [0 2] ( 0 .. 2 )
row_i 1 col_index [2] ( 2 .. 3 )
row_i 2 col_index [0 1 2] ( 3 .. 6 )

In [12]:
mat.todense()


Out[12]:
matrix([[1, 0, 2],
        [0, 0, 3],
        [4, 5, 6]])

In [ ]: