MathGroup Archive 2009

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

Search the Archive

Re: Mapping to a specific column or row in a matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103287] Re: Mapping to a specific column or row in a matrix
  • From: John Jowett <john.m.jowett at gmail.com>
  • Date: Sun, 13 Sep 2009 08:01:44 -0400 (EDT)
  • References: <h7qem5$us$1@smc.vnet.net> <h8an76$h86$1@smc.vnet.net>

Here are a few other methods which work:

I'm not sure why this method works.  Perhaps someone can clarify?

mat = ConstantArray[1, {10, 5}];;
mat[[All, 3]] = mat[[All, 3]]/10;
mat

In this method (which I use a lot), the rule depends on the structure
and its contents

mat = ConstantArray[1, {10, 5}];
mat = mat /. {a_, b_, x_Integer, c__} :> {a, b, x/10, c}


This method feels safe but I don't like it and it may be inefficient:

mat = ConstantArray[1, {10, 5}];
Do[mat = ReplacePart[mat, {k, 3} -> mat[[k, 3]]/10], {k, 1, 10}];
mat

John Jowett



On Sep 10, 1:16 pm, dr DanW <dmaxwar... at gmail.com> wrote:
> You are correct that you need a combination of Map and MapAt.
> Specifically, you need the position spec from MapAt with the level
> spec from Map.
>
> MapAtLevel[f_, expr_, n_, levelspec_: {1}] :=
>  Map[MapAt[f, #, n] &, expr, levelspec - 1]
>
> It looks like you did this, but called it clunky.  By creating a new
> function, it becomes much less clunky.  I often have to plot data from
> a list of {x,y} pairs, but I want to transform all the y values to
> decibel:
>
> dat = {{1, 200.}, {2, 250.}, {3, 300.}};
>
> In[30]:= MapAtLevel[20 Log[10, #] &, dat, 2, 2]
>
> Out[30]= {{1, 46.0206}, {2, 47.9588}, {3, 49.5424}}
>
> Daniel



  • Prev by Date: So i can ask questions via this mail? How to remove the time tag in
  • Next by Date: Re: Changing style of autogenerated messages in Mathematica 7
  • Previous by thread: Re: Mapping to a specific column or row in a matrix
  • Next by thread: Re: Re: Mapping to a specific column or row in a matrix