import numpy as np
from scipy.sparse import csr_matrix
# Numpy array with a few non-zero values
a = np.array([[0,0,0,0,1], [0,2,0,0,0], [0,0,0,3,0], [4,0,0,0,0], [0,0,5,0,6], [0,0,7,0,0], [0,8,0,9,0]])
# find the indices of the cell where value is non-zero
row, col = np.where(a!=0)
cellValue = np.array([a[i][j] for i,j in zip(row, col)])
# create a CSR sparse matrix of size 7x5
X = csr_matrix((cellValue, (row, col)), shape=(a.shape[0], a.shape[1]), dtype=np.int8)
print(X.toarray())