MathGroup Archive 2007

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

Search the Archive

Re: Selecting Sub-lists After Split

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77471] Re: Selecting Sub-lists After Split
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 9 Jun 2007 05:40:48 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f4b89h$3ls$1@smc.vnet.net>

Gregory Lypny wrote:
> Hello everyone,
> 
> 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?
> 
> Any tips would be most appreciated.
> 
> Regards,
> 
> 	Gregory 

Hi Gregory,

The expression Cases[myNewList, v_ /; VectorQ[v, Negative]] will do it.

In[1]:=
myList = RandomInteger[{-5, 5}, {20}]

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

Cases[myNewList, v_ /; VectorQ[v, Negative]]

Out[1]=
{-3, -5, 0, -2, 4, -1, -5, -3, -1, 0, -1, 4, 1, -3, 1, -3, 5, 4, 3, 5}

Out[2]=
{{-3, -5}, {0}, {-2}, {4}, {-1, -5, -3, -1}, {0}, {-1}, {4, 1}, {-3},
    {1}, {-3}, {5, 4, 3, 5}}

Out[3]=
{{-3, -5}, {-2}, {-1, -5, -3, -1}, {-1}, {-3}, {-3}}

Regards,
Jean-Marc


  • Prev by Date: Re: Selecting Sub-lists After Split
  • Next by Date: Re: Re: v6: still no multiple undo?
  • Previous by thread: Re: Selecting Sub-lists After Split
  • Next by thread: Re: Selecting Sub-lists After Split