Re: Problem with substitutions in SparseArray?
- To: mathgroup at smc.vnet.net
- Subject: [mg56907] Re: [mg56824] Problem with substitutions in SparseArray?
- From: arrigoni <arrigoni at itp.tu-graz.ac.at>
- Date: Tue, 10 May 2005 03:42:09 -0400 (EDT)
- References: <200505070816.EAA20188@smc.vnet.net> <6d5b1cedba1e6f5bbfe7eb5fd2f511bc@mimuw.edu.pl>
- Sender: owner-wri-mathgroup at wolfram.com
Thank you very much for your answer > > > (n = m /. HoldPattern[SparseArray[x__, {y__, {a}}]] :> > SparseArray[x, {y, {1}}])//InputForm > However, this is not very general. If you have, for example mm=SparseArray[{i_,i_}->a,{2,2}] (nn = mm /. HoldPattern[SparseArray[x__, {y__, {a}}]] :> SparseArray[x, {y, {1}}]) Normal[nn] RESULT: {{a, 0}, {0, a}} > > n=SparseArray[ArrayRules[m]/.a->1]//InputForm > > > SparseArray[Automatic, {1, 1}, 0, {1, {{0, 1}, {{1}}}, > {1}}] > With this one must be even more careful: in this case the zeroes of the matrix have been removed and you are left with a 1x1 instead of a 2x2 matrix I tried it this way, i. e. by defining a special replacement ReplaceSparse[ff_,rr_Rule] := (ff/.rr)/. HoldPattern[SparseArray[xx__]]:> SparseArray @@ ({xx}/.rr) but I don't like it very much EXAMPLES: ReplaceSparse[mm,a->1] //Normal ReplaceSparse[m,a->1] //Normal one could even think to redefine ReplaceAll in this way Enrico
- References:
- Problem with substitutions in SparseArray?
- From: Enrico Arrigoni <arrigoni@itp.tu-graz.ac.at>
- Problem with substitutions in SparseArray?