scipy.sparse
that provides functions to deal with sparse data. There are two types of sparse matrices that we use :scipy.sparse.csr_matrix()
.import numpy as np
from scipy.sparse import csr_matrix
arr = np.array([0, 0, 0, 0, 0, 1, 1, 0, 2])
print(csr_matrix(arr))
Output :
(0, 5) 1
(0, 6) 1
(0, 8) 2