Re: Selecting Sub-lists After Split

• To: mathgroup at smc.vnet.net
• Subject: [mg77466] Re: Selecting Sub-lists After Split
• From: Bill Rowe <readnewsciv at sbcglobal.net>
• Date: Sat, 9 Jun 2007 05:38:12 -0400 (EDT)

```On 6/8/07 at 5:34 AM, gregory.lypny at videotron.ca (Gregory Lypny)
wrote:

>Suppose I have a list of real number called myList.  I split it into
>sub-lists of positive and negative numbers called myNewList by doing
>this (there may be a more elegant way):

>myNewList = Split[myList, #1 #2 > 0 &]

>Now, how can I select all of the sub-lists of negative numbers from
>myNewList?

A simple way to do this would be to use pattern matching and Cases.

=46irst generate so data

In[12]:= data = Split[RandomReal[{-1, 1}, 20], #1 #2 > 0 &]

Out[12]= {{0.515309},{-0.014795},{0.329838,0.896598},{-0.414435,
-0.326671,-0.347789,-0.627698,-0.763855,-0.85736,-0.774624},{0.861427,
0.387308,0.590255},{-0.502033},{0.813789},{-0.748274,-0.297541,
-0.170911,-0.948834}}

then to pick out the sub-lists with negative values

In[13]:= Cases[data, {_?(# < 0 &), ___}]

Out[13]= {{-0.014795},{-0.414435,-0.326671,-0.347789,-0.627698,
-0.763855,-0.85736,-0.774624},{-0.502033},{-0.748274,-0.297541,-0.170911,
-0.948834}}
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: Re: v6: still no multiple undo?
• Next by Date: Re: Unable to copy graphics from Mathematica 6 to Publicon
• Previous by thread: Re: Selecting Sub-lists After Split
• Next by thread: Re: Selecting Sub-lists After Split