Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Apply function to parts of a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86272] Re: Apply function to parts of a list
  • From: "David Park" <djmpark at comcast.net>
  • Date: Fri, 7 Mar 2008 02:29:24 -0500 (EST)
  • References: <fqo8pn$svq$1@smc.vnet.net>

Here is a sample set of data:

data = Table[{i, 2 i}, {i, 1, 10}];

Since Times is Listable you can scale all the elements by 2 simply by 
writing:

2 data
{{2, 4}, {4, 8}, {6, 12}, {8, 16}, {10, 20}, {12, 24}, {14, 28}, {16,
  32}, {18, 36}, {20, 40}}

If you want to map a function f onto all the elements you can just use:

f /@ data
{f[{1, 2}], f[{2, 4}], f[{3, 6}], f[{4, 8}], f[{5, 10}], f[{6, 12}],
 f[{7, 14}], f[{8, 16}], f[{9, 18}], f[{10, 20}]}

I'm not certain why you used MapAt instead of the more direct Map.

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


"guerom00" <guerom00 at gmail.com> wrote in message 
news:fqo8pn$svq$1 at smc.vnet.net...
> 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.
> 



  • Prev by Date: Re: Apply function to parts of a list
  • Next by Date: Re: Assignment problem
  • Previous by thread: Re: Apply function to parts of a list
  • Next by thread: Re: Apply function to parts of a list