Re: Newbie question: pairswise function application
- To: mathgroup at smc.vnet.net
- Subject: [mg23979] Re: Newbie question: pairswise function application
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 18 Jun 2000 03:01:02 -0400 (EDT)
- References: <8i1t6n$jn9@smc.vnet.net> <Pine.GSO.4.21.0006131745370.18990-100000@flip.eecs.umich.edu> <tXg25.30$x6.4664@ralph.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
I have been concerned that the solution in my earlier posting did not give the requested order. The following slighty slower version does give the requested order and, on my tests, is about three times as fast as fastest other solution posted. pairs[data_, f_] := MapThread[f, {Join @@ (NestList[Rest, Table[1, {# - 1}], # - 2]Drop[data, -1]), Join @@ (NestList[Drop[#, 1] &, Drop[data, 1], # - 2]) } &[Length[data]] ] If only the pairs are needed then the following seems to be particularly fast pairs[data_] := Transpose[ {Join @@ (NestList[Rest, Table[1, {# - 1}], # - 2]Drop[data, -1]), Join @@ (NestList[Drop[#, 1] &, Drop[data, 1], # - 2]) } &[Length[data]] ] Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565