I’m looking for the most performant way to modify a large SparseMatrixCSC
in-place. The matrix is initially built using the sp = sparse(I,J,K)
method. Later, I need to modify only the non-zero entries in sp
. I’m tempted to do
sp.nzval .= newK
where newK
is the updated K
vector. This is really fast, but I worry this approach is fragile (as e.g. there are no guarantees that zeros in the original K are dropped when building the original sp
, or that the order of sp.nzval
is the same as in K
). Can this be made safe? If not, is there some recommended approach with comparable performance?