Apply&Map
- To: mathgroup at yoda.ncsa.uiuc.edu
- Subject: Apply&Map
- From: uunet!cup.portal.com!Alfy_N_Riddle
- Date: Sat, 2-Jun-90 02:12:43 PDT
Mathematica Users: Rather often I have had the need to apply a function, which had several arguments, to each row of a list. I will not mention the kludges I used to use to do this, but a friend helped me find what a solution which now looks all TOO obvious. It may be useful to others. In[1]:= fn @@ #& /@ {{1,2},{3,4}} Out[1] = {fn[1,2], fn[3,4]} This code maps a pure function over a matrix, and then applies the desired function, fn, to each row. If your function uses options you can use: In[2]:= fn[ ##, opt1->2 ] @@ #& /@ {{1,2},{3,4}} Out[2]= {fn[1,2,opt1->2], fn[3,4,opt1->2]} Best wishes, Alfy Riddle (alfy at cup.portal.com)