Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: Thread? Through? Operate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32398] RE: [mg32388] Thread? Through? Operate?
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
  • Date: Sat, 19 Jan 2002 01:16:31 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From:	Johannes Ludsteck [SMTP:johannes.ludsteck at wiwi.uni-regensburg.de]
To: mathgroup at smc.vnet.net
> To:	mathgroup at smc.vnet.net
> Subject:	[mg32388] Thread? Through? Operate?
> 
> 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
> 
> 
[Hartmut Wolf]  

Johannes,

elegance is a questionable, at least unclear goal. 


I think your solution

Map[#[[1]][#[[2]]]&,Transpose[{{f1,f2,f3},{x1,x2,x3}}]]


is quite acceptable; I just would rewrite it as 

Apply[#1[#2]&,Transpose[{{f1,f2,f3},{x1,x2,x3}}],{1}]


There are alternatives of course, here are some of them


Inner[#1[#2]&,{f1,f2,f3},{x1,x2,x3},List]

Thread[Unevaluated[#1[#2]&[{f1,f2,f3},{x1,x2,x3}]]]

MapThread[#1[#2]&,{{f1,f2,f3},{x1,x2,x3}}]


Inner[Apply,{f1,f2,f3},Thread[Null[{x1,x2,x3}]],List]

Inner[Apply,{f1,f2,f3},Null/@{x1,x2,x3},List]

Unevaluated[Thread[Unevaluated[Apply[{f1,f2,f3},xx]]]]/.xx->
    Transpose[{{x1,x2,x3}}]

MapThread[Apply,{{f1,f2,f3},Transpose[{{x1,x2,x3}}]}]


You can build more variants from this. If you have to work 
with held arguments (Map)Threading Apply seems to be most 
attractive, supposed your Arguments come wrapped with Hold 
or something equivalent.

-- 
Hartmut Wolf






  • Prev by Date: Re: path problem
  • Next by Date: Re: path problem
  • Previous by thread: Re: Thread? Through? Operate?
  • Next by thread: Exploring Analytic Geometry by Vossler