Re: Apply function to parts of a list
- To: mathgroup at smc.vnet.net
- Subject: [mg86242] Re: [mg86224] Apply function to parts of a list
- From: "Thomas Dowling" <thomasgdowling at gmail.com>
- Date: Fri, 7 Mar 2008 02:23:48 -0500 (EST)
- References: <200803060759.CAA29253@smc.vnet.net>
Hello,
I am sure you will get many replies!
Nevertheless ...
list = {{x1, y1}, {x2, y2}, {x3, y3}, {xn, yn}}
1. Using Apply
{2 #1 , #2 } & @@@ list
Out[34]= {{2 x1, y1}, {2 x2, y2}, {2 x3, y3}, {2 xn, yn}}
or
Apply[{2 #1 , #2 } &, list, {1}]
2. Replacement rules can sometimes be convenient.
list /. {x_, y_ } -> {2 x, y }
I look forward to reading the (many?) other suggestions ...
Tom Dowling
On Thu, Mar 6, 2008 at 7:59 AM, guerom00 <guerom00 at gmail.com> wrote:
> Hi all,
>
> Very often, I find myself having datas to plot of this form :
>
> data={{x1,y1},{x2,y2},{x3,y3}...{xn,yn}}
>
> So, very conventional : a list of abscissa and ordinate. Now, let's say I
> want to multiply by 2 all my ascissa. Right now, I write :
>
> MapAt[2*#&,data,Table[{i,1},{i,1,Length[data]}]]
>
> It's OK but I isn't there another way to achieve this as I find this
> rather "involved" for such a simple thing ?
>
> Thanks in advance.
>
- References:
- Apply function to parts of a list
- From: guerom00 <guerom00@gmail.com>
- Apply function to parts of a list