MathGroup Archive 2009

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

Search the Archive

Re: list/sequence problem: a 'keep' list to a list of 'kept' lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97282] Re: list/sequence problem: a 'keep' list to a list of 'kept' lists
  • From: dh <dh at metrohm.com>
  • Date: Tue, 10 Mar 2009 05:33:05 -0500 (EST)
  • References: <goqphg$lss$1@smc.vnet.net>


Hi,

assume p and d are prior-vector and data:

p = {False, True, False, True, False, False, True, True, True, False,

    True};

d = Table[i, {i, Length[p]}];

we then construct data items {dat,boolean} and put them in a 

list:{{dat,boolean}. Next we apply repeatedly  a rule that considers two 

neighbours and appends the left neighbor to the list of the right one if 

the right list consists of one item with boolean value of True. Last, we 

pick out the data values:



t = t //. {x1 : ___, x2 : {__}, x3 : {{_, True}}, x4___} :> {x1, x2,

      Append[x2, x3[[1]]], x4} ;

t[[All, All, 1]]



hope this helps, Daniel



mkr wrote:

> I have a list of Booleans, indicating whether prior values in sequence

> are to be 'kept'.  I want to generate a list of accumulated 'kept'

> positions for each position in the sequence.  The following code

> works, but I would love to see a cleaner, more obivous approach.

> Anyone?

> 

> In[]=

> 

> keepPrior=

> {False,True,False,True,False,False,True,True,True,False,True};

> 

> keptPriors=Function[aclist,If[Split[aclist][[-1,1]]==True,Range[Length

> [aclist]-Length[Split[aclist][[-1]]],Length[aclist]],{Length

> [aclist]}]]/@Rest[FoldList[Append,{},keepPrior]];

> 

> TableForm[Transpose[{keepPrior,ToString/@keptPriors}],TableHeadings->

> {Automatic,None}]

> 

> 

> Out[]=

> 

> 1	False	{1}

> 2	True	{1, 2}

> 3	False	{3}

> 4	True	{3, 4}

> 5	False	{5}

> 6	False	{6}

> 7	True	{6, 7}

> 8	True	{6, 7, 8}

> 9	True	{6, 7, 8, 9}

> 10	False	{10}

> 11	True	{10, 11}

> 

> 




  • Prev by Date: Re: Notebook that auto-executes when opened?
  • Next by Date: Re: Re: Re: Re: Re:
  • Previous by thread: Re: list/sequence problem: a 'keep' list to a list of
  • Next by thread: Bug In LogPlots with WorkingPrecision option?