Re: Map onto a column
- To: mathgroup at smc.vnet.net
- Subject: [mg125478] Re: Map onto a column
- From: Dana DeLouis <dana01 at me.com>
- Date: Thu, 15 Mar 2012 00:29:35 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
> b = Map[MapAt[f,#,2]&,a] > b = MapAt[f,a,{All,2}] (...error) > > Is there any way to do what I want with a single Map/MapAt function? Hi. Just another option: m = {{1,2,3},{4,5,6},{7,8,9}}; m[[All,2]] = f/@m[[All,2]]; // or m[[All,2]] = Map[f, m[[All,2]]]; m {{1,f[2],3},{4,f[5],6},{7,f[8],9}} = = = = = = = = = = HTH :>) Dana DeLouis Mac & Math 8 = = = = = = = = = = On Mar 13, 4:04 am, Sly Pandemia <slypande... at gmail.com> wrote: > Is there a neat way to map a function onto a specific column in an > array? > > For example if I have > > a = {{1,2,3},{4,5,6},{7,8,9}} > > and I want to map f onto the second element in each row. I would > normally use > > b = Map[MapAt[f,#,2]&,a] > > but this seems a bit awkward. I would expect to be able to use > > b = MapAt[f,a,{All,2}] > > but this appears to be illegal syntax. > > Is there any way to do what I want with a single Map/MapAt function?