Re: Mapping Functions That Take More Than One Argument

*To*: mathgroup at smc.vnet.net*Subject*: [mg69897] Re: [mg69864] Mapping Functions That Take More Than One Argument*From*: Gregory Lypny <gregory.lypny at videotron.ca>*Date*: Wed, 27 Sep 2006 06:03:54 -0400 (EDT)*References*: <NDBBJGNHKLMPLILOIPPOOEOAFCAA.djmp@earthlink.net>

Excellent. Thank you, David. My collection of MathGroup tips is growing and growing. Gregory On Tue, Sep 26, 2006, at 10:03 AM, David Park wrote: > Gregory, > > To map a function with more than one argument over a list, use a pure > function with the other arguments filled in. > > testlist = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; > > Map[Drop[#, 1] &, testlist] > {{2, 3}, {5, 6}, {8, 9}} > > Or > > Drop[#, 1] & /@ testlist > {{2, 3}, {5, 6}, {8, 9}} > > Suppose you want to map over two lists, one for each argument? > Suppose you > want to drop 1 argument in the first list, 2 arguments in the > second list, > and the last argument in the third list. Do it with a pure function > and > MapThread. > > MapThread[Drop[#1, #2] &, {testlist, {1, 2, -1}}] > {{2, 3}, {6}, {7, 8}} > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > > > > > From: Gregory Lypny [mailto:gregory.lypny at videotron.ca] To: mathgroup at smc.vnet.net > > Hello everyone, > > How can I map a functions onto sub-lists when the function takes more > than one argument. I can't seem to stumble upon the right syntax. > > Here's a list of three sub-lists. > > {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} > > I want to drop the first element of each sub-list, that is, 1 from > the first, 4 from the second, and 7 from the third. > > Drop[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 1] > > gives me > > {{4, 5, 6}, {7, 8, 9}}, > > which is what I expected (I'm learning) but not what I want. So, how > do I apply Drop to each sub-list? > > Regards, > > Gregory >