Re: Applying rules to SparseArray

• To: mathgroup at smc.vnet.net
• Subject: [mg66417] Re: Applying rules to SparseArray
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Thu, 11 May 2006 05:36:12 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e3um72\$hf4\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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 )
>
>
Hi CoolGenie,

Use the built-in function *Normal* [1] before applying the
transformation rule (see In[3]).

In[1]:=
m = SparseArray[{{1, 1} -> 1, {1, 2} -> 2,
{3, 2} -> x}, {3, 3}]

Out[1]=
SparseArray[]

In[2]:=
m//Normal//TableForm//OutputForm

Out[2]//OutputForm=
1   2   0

0   0   0

0   x   0

In[3]:=
m = SparseArray[Normal[m] /. x -> 1]

Out[3]=
SparseArray[]

In[4]:=
m//Normal//TableForm//OutputForm

Out[4]//OutputForm=
1   2   0

0   0   0

0   1   0

Best regards,
Jean-Marc

[1] http://documents.wolfram.com/mathematica/functions/Normal

```

• Prev by Date: Re: Applying rules to SparseArray
• Next by Date: Re: two graphics questions and one general question
• Previous by thread: Re: Applying rules to SparseArray
• Next by thread: Re: Applying rules to SparseArray