Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

Fw: Pattern Matching in Lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35572] Fw: [mg35547] Pattern Matching in Lists
  • From: "Julio Vera" <jvera at adinet.com.uy>
  • Date: Fri, 19 Jul 2002 06:08:54 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Anthony,

I should have gone a step further. Since you just want the number of
occurrences, we should apply Cases also, and transform the output into just
it´s first element.

In[2]:=
Cases[Frequencies[Partition[w,2,1]],{_Integer,{1,0}}]/.{a_,{b__}}->a

Out[2]=
{4}

Julio
----- Original Message -----
From: "Julio Vera" <jvera at adinet.com.uy>
To: mathgroup at smc.vnet.net
Subject: [mg35572] Re: [mg35547] Pattern Matching in Lists


> Anthony,
>
> Here´s how I´d do it.
>
> Load a package that contains the function Frequencies
> In[1]:=
> <<Statistics`DataManipulation`
>
> Then apply the function Frequencies to a Partition of w that contains
pairs
> of it´s elements, each of them starting with each of the elements of w
> (except the last one, since it doesn´t have one to follow it).
>
> In[2]:=
> Frequencies[Partition[w,2,1]]
>
> Out[2]=
> {{3,{0,0}},{4,{0,1}},{4,{1,0}},{2,{1,1}}}
>
> The third element of this list shows w contains 4 elements 1 that are
> followed by an element 0 .
>
> Julio
>
>
> >
> > ----- Mensaje original -----
> > De: "Anthony Mendes" <amendes at zeno.ucsd.edu>
> > Para: <mathgroup at smc.vnet.net>
> > Enviado: Jueves 18 de Julio de 2002 04:06 AM
> > Asunto: [mg35547] Pattern Matching in Lists
> >
> >
> > > Hello,
> > >
> > > Suppose w={1,1,1,0,0,1,0,1,0,0,1,0,0}.
> > >
> > > How can I count the number of occurrences of a 1 in w immediately
> > > followed by a 0 in w?
> > >
> > > I have tried every incarnation of Count[] I can think of; for example,
> > >
> > > Count[w,{___,1,0,___}]
> > >
> > > does not seem to work.  In general, how can I count the number of
> > > occurrences of a 1 followed by a 0 in a list of 1's and 0's?  Thank
you!
> > >
> > >
> > > --
> > > Tony
> > > _____________________
> > > amendes at math.ucsd.edu
> > >
> > >
> >
>



  • Prev by Date: RE: Re: Output of left-hand side of expression
  • Next by Date: RE: Pattern Matching in Lists
  • Previous by thread: RE: Pattern Matching in Lists
  • Next by thread: RE: Pattern Matching in Lists