Re: Applying rules to SparseArray
- To: mathgroup at smc.vnet.net
- Subject: [mg66414] Re: [mg66360] Applying rules to SparseArray
- From: Adriano Pascoletti <pascolet at dimi.uniud.it>
- Date: Thu, 11 May 2006 05:36:00 -0400 (EDT)
- References: <200605110613.CAA17020@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 11 mag 2006, at 08:13, CoolGenie wrote: > Hi! > Let's say I've a matrix like this one: > m=SparseArray[ {{1, 1} -> 1, {1, 2} ->2, {3, 2} -> x}, {3, 3} ]; > which looks like this in MatrixForm: > 1 2 0 > 0 0 0 > 0 x 0 > where 'x' is a variable coefficient. Is there any way to apply a rule > {x->1} to this array? ( m/.{x->1} doesn't work ) > > Thanks in advance > This defines the matrix In[56]:= m=SparseArray[ {{1, 1} -> 1, {1, 2} ->2, {3, 2} -> x}, {3, 3} ]; ArrayRules[m] Out[57]= {{1,1}\[Rule]1,{1,2}\[Rule]2,{3,2}\[Rule]x,{_,_}\[Rule]0} then replace x in ArrayRules In[58]:= SparseArray[ArrayRules[#]/.{x\[Rule]1},Dimensions[#]]&@m ArrayRules[%] Out[58]= SparseArray[<\[InvisibleSpace]3\[InvisibleSpace]>,{3,3}] Out[59]= {{1,1}\[Rule]1,{1,2}\[Rule]2,{3,2}\[Rule]1,{_,_}\[Rule]0} Adriano Pascoletti
- References:
- Applying rules to SparseArray
- From: "CoolGenie" <CGenie@gmail.com>
- Applying rules to SparseArray