I want to create sparse matrix sB from sparse matrix sA:
# create the example data
A = np.array([ [0, 2], [3, 0] ])
IdxP = np.array([9,100])
IdxN = np.array([50,30])
n, p = np.where(A)
sA = sparse.csr_matrix(A)
sB =sparse.lil_matrix((200,200))
sB[IdxP[p], IdxN[n]] = sA[p, n]
In the example, I use lil_matrix for sB and csr_matrix for sA for the indexing and assignment. Is there a better combination to make it faster?