Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Computing n-grams

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88913] Computing n-grams
  • From: "Coleman, Mark" <Mark.Coleman at LibertyMutual.com>
  • Date: Wed, 21 May 2008 14:49:40 -0400 (EDT)

Greetings,

Imagine one has a list such as {a,b,c,d,e,f,g}. I'm trying to find an
efficient way in Mathematica to compute the n-grams of the list. That is, for
n=2, the n-grams are all the lists of length 2 consisting of consecutive
elements, e.g.,

{a,b},{b,c},{c,d},{d,e},...

While for n=3,

{a,b,c},{b,c,d},{c,d,e},..., and so on.

As I understand it, the built-in Mathematica commands such as Subsets or
Permutations compute all possible list of size n, without regard to the
order of the list elements.

Thanks,

Mark



  • Prev by Date: Color space conversion in Mathematica v6.0
  • Next by Date: strange behaviour of Integration
  • Previous by thread: Re: Re: Color space conversion in Mathematica v6.0
  • Next by thread: Re: Computing n-grams