MathGroup Archive 2009

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

Search the Archive

Re: Map onto one column of a matrix

  • To: mathgroup at
  • Subject: [mg95674] Re: Map onto one column of a matrix
  • From: "Drago Ganic" <dganic at>
  • Date: Sat, 24 Jan 2009 06:21:16 -0500 (EST)
  • References: <gl49tb$g7v$> <gl71no$bvl$>

if you represent the matrix as a table/relation (Database` package of Roman 
E. Maeder) you could use his overloaded Table function. The solution is very 
elegant, but you need to name the columns (e.g. x,y or col1, col2 ). After 
naming the columns you use those names as function argumnets and don't need 
pure functions. You never need positional notiation.

In[1]:= << Database`
In[2]:= rel = newRelation[{x, y}, {{a, b}, {c, d}}];

In[3]:= Table[ {x, f[y]}, rel ]
Out[3]= {{a, f[b]}, {c, f[d]}}

Greetings from Croatia,
Drago Ganic

"Jens-Peer Kuska" <kuska at> wrote in message 
news:gl71no$bvl$1 at
> Hi,
> data = {{a, b}, {c, d}};
> MapAt[f, #, {-1}] & /@ data
> data /. {q_, r_?AtomQ} :> {q, f[r]}
> Regards
>   Jens
> . 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: Extracting Graphics3D from Plots
  • Next by Date: two graphs have different color on surface
  • Previous by thread: Re: Map onto one column of a matrix
  • Next by thread: production quality 2-D graphs with mathematica