MathGroup Archive 2010

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

Search the Archive

Re: How to apply a list of functions

Hi Vince,

First, you could use Compose in your code - perhaps it is a little faster:

In[2]:= MapThread[Compose,{{f1,f2,f3},{x1,x2,x3}}]

Out[2]= {f1[x1],f2[x2],f3[x3]}

Using Inner can be a bit faster still:

In[4]:= Inner[Compose,{f1,f2,f3},{x1,x2,x3},List]

Out[4]= {f1[x1],f2[x2],f3[x3]}

In most cases, you probably won't see the difference in performance, unless
your functions do very little and you have lots of them.


On Mon, Oct 4, 2010 at 2:06 PM, Vince Virgilio <blueschi at> wrote:

> On Oct 3, 3:39 am, Sam Takoy <sam.ta... at> wrote:
> > Hi,
> >
> > As a follow up to my question about apply {Sin, Cos} to x, I came up
> > with the tasteless
> >
> > Map[Apply[#, {x}] &, {Sin, Cos}]
> >
> > but I expect that the pros in this ng will be able to improve upon it.
> >
> > Thanks,
> >
> > Sam
> Tangentially,
> I've always wondered if there was a better way to apply a list of
> functions to a list of arguments. Here's how I do it, where f and x
> are the respective lists.
> MapThread[#1@#2 &, {f, x}]
> Seems performant.
> Anyone?
> Vince

  • Prev by Date: Re: How to interpolate vectors?
  • Next by Date: Re: Plotting a function dynamically in a loop
  • Previous by thread: Re: How to apply a list of functions
  • Next by thread: Re: How to apply a list of functions