How to efficiently assign a value to a scipy sparse matrix like A[2,3]=1?

Viewed 30

It seems that assigning values to a scipy.sparse.csr_matrix element causes me a warning:

In [25]: A=csr_matrix((100000,100000),dtype=float)

In [26]: A[2,3]=1
/opt/miniconda3/lib/python3.9/site-packages/scipy/sparse/_index.py:103: SparseEfficiencyWarning: Changing the sparsity structure of a csr_matrix is expensive. lil_matrix is more efficient.
 

How can I do the simple "A[2,3]=1" assignment?

0 Answers
Related