Re: Thread and MapThread
- To: mathgroup at smc.vnet.net
- Subject: [mg29874] Re: [mg29868] Thread and MapThread
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Sun, 15 Jul 2001 00:59:00 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
The problem is that both functions Thread and MapThread evaluate their arguments. In the case of MapThread and this particular example it is harmless but it the case of Thread this is what happens: In[10]:= Thread[ftest[{x1, x2, x3}, {y1, y2, y3}]]//Trace Out[10]= {{ftest[{x1,x2,x3},{y1,y2,y3}],{f1[{x1,x2,x3}],f2[{y1,y2,y3}]}}, Thread[{f1[{x1,x2,x3}],f2[{y1,y2,y3}]}],{f1[{x1,x2,x3}],f2[{y1,y2,y3}]}} So what you need to do is: In[11]:= Thread[Unevaluated[ftest[{x1, x2, x3}, {y1, y2, y3}]]] Out[11]= {{f1[x1],f2[y1]},{f1[x2],f2[y2]},{f1[x3],f2[y3]}} -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ http://sigma.tuins.ac.jp/~andrzej/ on 01.7.14 2:36 PM, David Park at djmp at earthlink.net wrote: > Dear MathGroup, > > Here is a function: > > ftest[x_, y_] := {f1[x], f2[y]} > > Why does the following work... > > MapThread[ftest, {{x1, x2, x3}, {y1, y2, y3}}] > {{f1[x1], f2[y1]}, {f1[x2], f2[y2]}, {f1[x3], f2[y3]}} > > ...but the following does not work. > > Thread[ftest[{x1, x2, x3}, {y1, y2, y3}]] > {f1[{x1, x2, x3}], f2[{y1, y2, y3}]} > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > >