Re: Map onto a column
- To: mathgroup at smc.vnet.net
- Subject: [mg125498] Re: Map onto a column
- From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
- Date: Thu, 15 Mar 2012 00:36:33 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
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?
Try this:
a={{1,2,3},{4,5,6},{7,8,9}}
a//MatrixForm
{{1,2,3},{4,5,6},{7,8,9}}
(1 2 3
4 5 6
7 8 9)
Map[f,Transpose[a][[2]]]
{f[2],f[5],f[8]}
Have fun.
Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG
Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44
e-mail: alexei.boulbitch at iee.lu<mailto:alexei.boulbitch at iee.lu>