Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9025
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Map onto a column |
| Date | 2012-03-14 05:43 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jjpb5v$p7u$1@smc.vnet.net> (permalink) |
On 3/13/12 at 3:02 AM, slypandemia@gmail.com (Sly Pandemia) 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?
Here is one way. But I don't that it will be any more
satisfactory to you
MapAt[f, a, Table[{n, 2}, {n, 3}]]
And to show this is the same
In[4]:= MapAt[f, a, Table[{n, 2}, {n, 3}]] == Map[MapAt[f, #, 2]
&, a]
Out[4]= True
Or how about re-writing your solution as
MapAt[f,#,2]&/@a
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Map onto a column Bill Rowe <readnews@sbcglobal.net> - 2012-03-14 05:43 +0000
csiph-web