MathGroup Archive 2010

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

Search the Archive

Re: Re: Re: position of sequence of

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107023] Re: [mg107012] Re: [mg106993] Re: [mg106976] position of sequence of
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Mon, 1 Feb 2010 06:09:29 -0500 (EST)
  • References: <201001301212.HAA25132@smc.vnet.net>

Hi Patrick,

and therefore, my next guess would have been something like
>
> pos[l_List, what_List] :=
>  ReplaceList[
>  l, {head___, Sequence @@ what, ___} :> Length[{head}] + 1]
>
>
Well, I wish my next guess would be this. I used this idiom before but it is
not in my active vocabulary, so instead I made a mess with Compile and
wasted lots of time - mine and all those who read my posts.

Regards,
Leonid



>
>
>
> > and therefore, your constructs don't seem to work for me. They seem to
> work
> > only because you provided length - 2 or length- 3 sequences (try length-4
> > and I am getting en error for v7), which Position interprets as 2 or 3
> > additional arguments. Thus,
> >
> > Position[list, Sequence[11, 12, 13]] is equivalent to
> >
> > Position[list, 11,12,13], which means:
> >
> > find position of element <11> in the first 12 levels of expression
> (<list>),
> > stopping with at most 13 results. By accident (or luck), this gives
> correct
> > result on the toy example that you have. The same situation with Bob's
> > example Position[list, Sequence[3, 4]].
> > Or is this an extension of v.7.1, that I am not aware of?
> >
> > Regards,
> > Leonid
> >
> > On Sun, Jan 31, 2010 at 2:55 AM, Patrick Scheibe <
> > pscheibe at trm.uni-leipzig.de> wrote:
> >
> > > Hi,
> > >
> > > I assume the only thing you miss is how to express a "sequence of
> > > numbers"? Just use Sequence[] :-)
> > >
> > > list=Range[20];
> > > Position[list, Sequence[11, 12, 13]]
> > >
> > > Cheers
> > > Patrick
> > >
> > > On Sat, 2010-01-30 at 07:12 -0500, JB wrote:
> > > > Hi,
> > > >
> > > > What is the most efficient way to find the position of the beginning
> > > > of a sequence of numbers from a list?
> > > >
> > > > I found a couple of ways:
> > > >
> > > > find 3,4 in list={1,2,3,4,5};
> > > >
> > > >  1.   pos=Intersection[Position[list,3],(Position[list,4])+1]
> > > >
> > > >  2.   pos=Position[Partition[list,2,1],{3,4}]
> > > >
> > > > Are there other ways to do this?
> > > > What is the best way when dealing with large lists?
> > > >
> > > > Thanks,
> > > > JB
> > > >
> > >
> > >
> > >
> >
>
>

--002354530710f4c28a047e794078
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Sun-Content-Length: 3159

Hi Patrick, <br><br><div class="gmail_quote"><blockquote class="gmail_q=
uote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0=
pt 0.8ex; padding-left: 1ex;">
and therefore, my next guess would have been something like<br>
<br>
pos[l_List, what_List] :=<br>
 ReplaceList[<br>
  l, {head___, Sequence @@ what, ___} :&gt; Length[{head}] + 1]<br>
<br></blockquote><div><br>Well, I wish my next guess would be this. I used =
this idiom before but it is not in my active vocabulary, so instead I made =
a mess with Compile and wasted lots of time - mine and all those who read m=
y posts.<br>
<br>Regards,<br>Leonid <br><br> </div><blockquote class="gmail_quote" s=
tyle="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8e=
x; padding-left: 1ex;">
<font color="#888888"><br>
</font><div><div class="h5"><br>
<br>
&gt; and therefore, your constructs don&#39;t seem to work for me. They see=
m to work<br>
&gt; only because you provided length - 2 or length- 3 sequences (try lengt=
h-4<br>
&gt; and I am getting en error for v7), which Position interprets as 2 or 3=
<br>
&gt; additional arguments. Thus,<br>
&gt;<br>
&gt; Position[list, Sequence[11, 12, 13]] is equivalent to<br>
&gt;<br>
&gt; Position[list, 11,12,13], which means:<br>
&gt;<br>
&gt; find position of element &lt;11&gt; in the first 12 levels of expressi=
on (&lt;list&gt;),<br>
&gt; stopping with at most 13 results. By accident (or luck), this gives co=
rrect<br>
&gt; result on the toy example that you have. The same situation with Bob&#=
39;s<br>
&gt; example Position[list, Sequence[3, 4]].<br>
&gt; Or is this an extension of v.7.1, that I am not aware of?<br>
&gt;<br>
&gt; Regards,<br>
&gt; Leonid<br>
&gt;<br>
&gt; On Sun, Jan 31, 2010 at 2:55 AM, Patrick Scheibe &lt;<br>
&gt; <a href="mailto:pscheibe at trm.uni-leipzig.de">pscheibe at trm.uni-leipzi=
g.de</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Hi,<br>
&gt; &gt;<br>
&gt; &gt; I assume the only thing you miss is how to express a &quot;sequen=
ce of<br>
&gt; &gt; numbers&quot;? Just use Sequence[] :-)<br>
&gt; &gt;<br>
&gt; &gt; list=Range[20];<br>
&gt; &gt; Position[list, Sequence[11, 12, 13]]<br>
&gt; &gt;<br>
&gt; &gt; Cheers<br>
&gt; &gt; Patrick<br>
&gt; &gt;<br>
&gt; &gt; On Sat, 2010-01-30 at 07:12 -0500, JB wrote:<br>
&gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; What is the most efficient way to find the position of the b=
eginning<br>
&gt; &gt; &gt; of a sequence of numbers from a list?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I found a couple of ways:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; find 3,4 in list={1,2,3,4,5};<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;  1.   pos=Intersection[Position[list,3],(Position[list=
,4])+1]<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;  2.   pos=Position[Partition[list,2,1],{3,4}]<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Are there other ways to do this?<br>
&gt; &gt; &gt; What is the best way when dealing with large lists?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Thanks,<br>
&gt; &gt; &gt; JB<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
<br>
</div></div></blockquote><br></div><br>

--002354530710f4c28a047e794078--


  • Prev by Date: Re: How to combine graphics pimitives and Plot function?
  • Next by Date: Re: Numerical Problem
  • Previous by thread: Re: Using variable name as string AND value ?
  • Next by thread: Re: Numerical Problem