MathGroup Archive 2001

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

Search the Archive

Re: Thread and MapThread

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29873] Re: [mg29868] Thread and MapThread
  • From: BobHanlon at aol.com
  • Date: Sun, 15 Jul 2001 00:59:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2001/7/14 1:58:47 AM, djmp at earthlink.net writes:

>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}]}
>

In your second case, when the argument to Thread is evaluated before Thread 
is applied, it is a List (the result) on which Thread has no effect.  You may 
want to make ftest Listable in which case the effects of MapThread occur 
automatically.

SetAttributes[ftest, Listable]

ftest[x_, y_] := {f1[x], f2[y]};

MapThread[ftest, {{x1, x2, x3}, {y1, y2, y3}}] ==  
  ftest[{x1, x2, x3}, {y1, y2, y3}]

True


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: about ConstrainedMin
  • Next by Date: Re: Thread and MapThread
  • Previous by thread: Thread and MapThread
  • Next by thread: Re: Thread and MapThread