Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9038 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2012-03-14 05:50 +0000 |
| Last post | 2012-03-14 05:50 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Map onto a column Bob Hanlon <hanlonr357@gmail.com> - 2012-03-14 05:50 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2012-03-14 05:50 +0000 |
| Subject | Re: Map onto a column |
| Message-ID | <jjpbig$pbj$1@smc.vnet.net> |
a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
col = 2;
With just MapAt:
MapAt[f, a, Thread[{Range[Length[a]], col}]]
{{1, f[2], 3}, {4, f[5], 6}, {7, f[8], 9}}
However, the abbreviated form of your original approach is much cleaner
MapAt[f, #, col] & /@ a
{{1, f[2], 3}, {4, f[5], 6}, {7, f[8], 9}}
Bob Hanlon
On Tue, Mar 13, 2012 at 4:02 AM, Sly Pandemia <slypandemia@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?
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web