MathGroup Archive 2007

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

Search the Archive

Re: split again

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73693] Re: split again
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Sat, 24 Feb 2007 02:30:10 -0500 (EST)

On 2/23/07 at 4:36 AM, Arkadiusz.Majka at gmail.com wrote:

>Thank you very much for your help in my provious post. Now, consider
>please a list

>z=Table[Random[],{1000}];

>zSplit=Split[z,#1<=0.7 === #2>=0.7];           (bulit thanks t=
o your
>help)

>I want to pick the first sublist of zSplit that consists of elements
><= 0.7 and whose length is greater than a certain number (say 5). I
>think that a good candidate would be using Cases and variations of _
>, but I don't know how.

What you posted doesn't seem to do what you describe. That is

In[24]:=
Split[Table[Random[], {10}], #1 <= 0.7 === #2 >= 0.7 & ]

Out[24]=
{{0.485581},{0.0582696},{0.0355538},{0.26509},{0.0298827,0.779148,0.0770904=
,
0.855232,0.0559297},{0.638716}}

Note with this test, the third sublist contains elements greater
than 0.7

Changing the test to:

In[25]:=
Split[Table[Random[], {10}], #1 <= 0.7 && #2 <= 0.7 & ]

Out[25]=
{{0.93307},{0.478675,0.145163,0.513827,0.526321,0.00400982},{0.740881},{0.\
759314},{0.904306},{0.59457}}
does what you say you want.

>What I want to do (and what my both posts are about) is to find the
>first sublist of z with all elements less than A and the length of
>this sublist must be greater than B. Maybe there exists better
>solution than to Split z in advance since what I need to do in my
>next step is to find ONLY the FIRST sublist of splitted z.

Either Cases or Select will work here. First with Cases:

In[26]:=
z = Table[Random[], {1000}];
zSplit = Split[z, #1 <= 0.7 && #2 <= 0.7 & ];
Cases[zSplit, _?(Length[#1] > 5 & )][[1]]

Out[28]=
{0.255395,0.374394,0.402473,0.25127,0.197126,0.338841,0.137383,0.221387,
0.417978,0.26175,0.28215,0.165457}


or with Select

In[29]:=
Select[zSplit,Length[#1]>5&][[1]]

Out[29]=
{0.255395,0.374394,0.402473,0.25127,0.197126,0.338841,0.137383,0.221387,
0.417978,0.26175,0.28215,0.165457}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: split again
  • Next by Date: simple question
  • Previous by thread: Re: split again
  • Next by thread: MatrixRank Modulus->8 - BUG