MathGroup Archive 2006

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

Search the Archive

Re: Question on Thread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64436] Re: Question on Thread
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 17 Feb 2006 04:11:43 -0500 (EST)
  • References: <dt1cs8$60$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hello Matt,
I have never fully understood Threads sometime strange behaviour. In any 
case, MapThread gives me much less trouble and can do everything Thread can.
Your example would then read:
Clear[f, g]
MapThread[(f[g[#1], #2] &), {{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}}]

and this does what one would expect.

Daniel

Matt wrote:
> Hello,
> 
> Clear[f]
> Thread[(f[#1, #2] & )[{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}]]
> 
> Gives the expected output, i.e. {f[1,{a,1}], f[2,{b,2}],...}
> 
> but
> 
> Clear[f, g]
> Thread[(f[g[#1], #2] & )[{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}]]
> 
> gives me:
> 
> f[g[{1, 2, 3}], {a, 1}], f[g[{1, 2, 3}], {b, 2}], ..., etc.
> 
> whereas I would have expected:
> 
> f[g[1], {a, 1}], f[g[2], {b, 2}], ..., etc.
> 
> I've looked at the 'Thread' documentation and in the Mathematica Book,
> but I can't see why the second case doesn't work.
> 
> BTW, I used MapThread as follows, which does work:
> 
> MapThread[f[g[#1], #2] & , {{1, 2, 3}, {{a, 1}, {b, 2}, {c, 3}}}
> 
> Thanks for your time,
> 
> Matt
> 


  • Prev by Date: Re: Mathematica:recursion with 2 arguments?
  • Next by Date: Re: Using a text editor like interface for Mathematica?
  • Previous by thread: Re: Question on Thread
  • Next by thread: Re: Question on Thread