MathGroup Archive 1999

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

Search the Archive

Re: Help to clarify 'Map', 'Apply', and 'Thread'.

  • To: mathgroup at
  • Subject: [mg15716] Re: Help to clarify 'Map', 'Apply', and 'Thread'.
  • From: phbrf at (Peter Breitfeld)
  • Date: Fri, 5 Feb 1999 03:42:15 -0500 (EST)
  • Organization: das ist ein breites Feld ...
  • References: <78uj8q$>
  • Sender: owner-wri-mathgroup at

Wen-Feng Shaw <wfshaw at> schrieb:
> Hi experts,
>    The functions 'Map', 'Apply', 'Thread', and 'MapThread' are very 
> useful. However, I am often confused by their functionalities. I often 
> should stop to try if a certain expression is correct before coding it 
> into my program. Could you help me to clarify them? Thanks a lot!
> Best Regards,
> Wen-Feng Shaw

Suppose you have
X={x,y,z}; A={a,b,c};

Apply changes the head of the expression: Apply[Subtract,eq]----->
Apply[Plus,{1,2,3,4}]----->10  (old head was List, new head is Plus) 

Map works on the elements in the first level of the expression:
Map[#+3&,eq] ---> 3+2x+3y==3+3   (added 3 on both sides)

MapAt works on the elements at a specified position:
MapAt[k#&,eq,{1,2}]-----> 2x+3ky==z (second element on left side times

Thread is hard to explain, but is changes eg "{a,b,c} operator {x,y,z}"
to "{a operator x, b operator y, c operator z}", so

eq /. Thread[X->A] -----> 2a+3b=c,   (eq/.X->A does nothing)

MapThread I have never used, but AFAIK it works on a list of lists.
MapThread[Plus,{X,A}] ----->{x+a,y+b,z+c}

es gruesst
  Peter Breitfeld, Saulgau, Germany       (PGP public key: 08548045)

  • Prev by Date: Bug in Utilities`BinaryFiles`
  • Next by Date: Re: Help to clarify 'Map', 'Apply', and 'Thread'.
  • Previous by thread: RE: Help to clarify 'Map', 'Apply', and 'Thread'.
  • Next by thread: Re: Help to clarify 'Map', 'Apply', and 'Thread'.