MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Applying rules to SparseArray

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66430] Re: Applying rules to SparseArray
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 12 May 2006 02:03:13 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 5/11/06 at 2:13 AM, CGenie at gmail.com (CoolGenie) wrote:

>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 )

This can be done as follows:

In[10]:=
m /. SparseArray[a_, b_, c_, d_] :> SparseArray[a, b, c, 
    d /. x -> 1]

Out[10]=
SparseArray[<\[InvisibleSpace]3\[InvisibleSpace]>,{3,3}]

In[11]:=
Normal@%

Out[11]=
{{1, 2, 0}, {0, 0, 0}, {0, 1, 0}}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Beginner--How to simulate multiple returns for a function?
  • Next by Date: Re: Recursion inspection technique : HoldForm but release variables
  • Previous by thread: Re: Applying rules to SparseArray
  • Next by thread: why doesn't the range on this interval match the plot range?