>>> import numpy as np
>>> from scipy.sparse import csr_matrix
>>> import pandas as pd
>>> r = np.array([0, 0, 1, 1, 2, 2, 2, 3, 4, 4, 5, 6, 6])
>>> c = np.array([0, 3, 4, 1, 3, 5, 6, 3, 1, 6, 0, 1, 3])
>>> data = np.array([1]*len(r))
>>> X = csr_matrix((data, (r, c)), shape=(7, 7))
>>> X
<7x7 sparse matrix of type '<class 'numpy.int64'>'
with 13 stored elements in Compressed Sparse Row format>
>>> Y=X.todense()
>>> Y
matrix([[1, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 0, 1, 1],
[0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0]])
>>> Z=X.toarray()
>>> Z
array([[1, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 0, 1, 1],
[0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0]])