given a SparseArray
s = SparseArray[{1, 10} -> 1, {1, 10}, a]
I can extract the background value (see What are SparseArray Properties? How and when should they be used? )
s["Background"]
a
but is there a direct way to change it? We can of course convert to Normal
form and create a new SparseArray
SparseArray[Normal[s] /. a -> b, Dimensions[s], b]
but note this will also change values that are explicitly a
, and is undesirable in case the array is really big and really sparse then passing through the normal form is unwieldy.
Best I've come up with is to do FullForm
and manually edit the third argument..
come up with an answer this, you can also answer this: Why does WeightedAdjacencyMatrix take the weight for absent edges to be zero?
s1 = ArrayRules[s] /. s["Background"] -> newBackground // SparseArray
? $\endgroup$SparseArray
objects where changed to atomic expressions I think.. $\endgroup$