MathGroup Archive 2002

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

Search the Archive

Re: Thread? Through? Operate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32399] Re: Thread? Through? Operate?
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 19 Jan 2002 01:16:33 -0500 (EST)
  • References: <a28b6v$h3h$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Johannes,
The following seem to be faster

    fns={f,g,h};
    args={a,b,c};

    Thread[Unevaluated[#1[#2]&[#1,#2]]]&[fns,args]

        {f[a],g[b],h[c]}

    MapThread[#[#2]&,{fns,args}]

        {f[a],g[b],h[c]}

    Inner[#1[#2] &, fns, args, List]

        {f[a],g[b],h[c]}

I use the outer function in the first one to put the evaluated fns and args
inside Thread.
We can make the other two into stand-alone functins in the same way, for
example

MapThread[#[#2]&,{#1,#2}]&[fns,args]

{f[a],g[b],h[c]}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Johannes Ludsteck" <johannes.ludsteck at wiwi.uni-regensburg.de> wrote in
message news:a28b6v$h3h$1 at smc.vnet.net...
> Dear MathGroup members,
> I have a list of n unnamed functions
>
> f = {expr1 &, expr2 &,... ,exprn &}
> (each function has exactly one arguement.
> and a list of n arguments.
>
> arg = {arg1, arg2,... ,argn}
>
> I simply want to apply each function expri &
> to the respective argument argi in order
> to obtain the list of function values fi.
> Is there no more elegant way than the following one?
>
> Map[#[[1]][#[[2]]]&, Transpose[{f,arg}]
>
> Thanks,
> Johannes
>
> <><><><><><><><><><><><><><><><><><>
> Johannes Ludsteck
> Institut fuer Volkswirtschaftslehre
> Lehrstuhl Prof. Dr. Moeller
> Universitaet Regensburg
> Universitaetsstrasse 31
> 93053 Regensburg
> Tel +49/0941/943-2741
>




  • Prev by Date: RE: Thread? Through? Operate?
  • Next by Date: Re: path problem
  • Previous by thread: RE: Thread? Through? Operate?
  • Next by thread: RE: Thread? Through? Operate?