Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg95535] Re: Map onto one column of a matrix
  • From: dh <dh at metrohm.com>
  • Date: Wed, 21 Jan 2009 06:44:21 -0500 (EST)
  • References: <gl49tb$g7v$1@smc.vnet.net>


Hi,

try:

data = {{a, b}, {c, d}};

data[[All, 2]] = f /@ data[[All, 2]] ;

data

hope this helps, Daniel



D. Grady 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

> 




  • Prev by Date: Re: problem importing an image
  • Next by Date: Re: Which editor do you use for math articles
  • Previous by thread: Re: Map onto one column of a matrix
  • Next by thread: Re: Map onto one column of a matrix