MathGroup Archive 2009

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

Search the Archive

Re: Map onto one column of a matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95546] Re: [mg95485] Map onto one column of a matrix
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 21 Jan 2009 06:46:23 -0500 (EST)
  • References: <200901201044.FAA16641@smc.vnet.net>
  • Reply-to: drmajorbob at longhorns.com

This might seem more intuitive:

data = {{a, b}, {c, d}}
Replace[data, {x_, y_} :> {x, f@y}, 1]

{{a, b}, {c, d}}

{{a, f[b]}, {c, f[d]}}

or

Transpose@{data[[All, 1]], f /@ data[[All, 2]]}

{{a, f[b]}, {c, f[d]}}

Bobby

On Tue, 20 Jan 2009 04:44:01 -0600, D. Grady <D.C.Grady at gmail.com> wrote:

> Hi, suppose we've got a matrix
>
> data = {{a, b}, {c, d}};
>
> and we want to map a function onto just the second column, so we want
> to end up with
>
> {{a, f[b]}, {c, f[d]}}.
>
> The best way I've found to do this is with MapAt:
>
> MapAt[f, data, Table[{i, 2}, {i, Length@data}]]
>
> Is there a better way?  I keep hoping there's some notation similar to
> what's used in Part that lets you refer to a whole column with All,
> like data[[All,2]].  Thanks!
>
> -Daniel
>



-- 
DrMajorBob at longhorns.com


  • Prev by Date: slots with 2 indexed array?
  • Next by Date: Re: What is QGamma[q,z]
  • Previous by thread: Re: Map onto one column of a matrix
  • Next by thread: Re: Map onto one column of a matrix