Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

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





  • Prev by Date: Re: is there really no efficient way to delete an element from a list??
  • Next by Date: Re: is there really no efficient way to delete an element from a list??
  • Previous by thread: Re: Newbie question: pairswise function application
  • Next by thread: Re: Newbie question: pairswise function application