Re: "In progress" saving of data collected using Reap/Sow

• To: mathgroup at smc.vnet.net
• Subject: [mg66217] Re: "In progress" saving of data collected using Reap/Sow
• Date: Thu, 4 May 2006 05:20:58 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

On 5/3/06 at 2:44 AM, koopman at sfu.ca (Ray Koopman) wrote:

>Expanding on my previous post, here are three ways to unravel z into
>a simple list of all the past results. The first way is fastest, but
>doesn't work if each result itself is a list.

You had suggested two methods for dealing with things when the result is a list, i.e.,

>        Nest[FlattenAt[#,1]&,z,n] === y
>        Table[Last@Nest[First,z,n-i],{i,n}] === y

If the result is a list with known constant length then it is much faster to do

Partition[Flatten@z, len] where len is the known constant len. For example,

In[27]:=
n = 10^3;
z = {}; Timing[Do[z = {z, {i, -i}}, {i, n}]; ]
Timing[a=Nest[FlattenAt[#1, 1] & , z, n]; ]
Timing[Table[Last[Nest[First, z, n - i]], {i, n}]; ]
Timing[b=Partition[Flatten[z], 2]; ]
a==b

Out[28]=
{0.003924 Second,Null}

Out[29]=
{0.062477 Second,Null}

Out[30]=
{0.387071 Second,Null}

Out[31]=
{0.001232 Second,Null}

Out[32]=
True
--
To reply via email subtract one hundred and four

• Prev by Date: Testing for squares
• Next by Date: Re: Selecting Many Things Rather Than Selecting One Thing From Many
• Previous by thread: Re: "In progress" saving of data collected using Reap/Sow
• Next by thread: Re: "In progress" saving of data collected using Reap/Sow