Re: Split in Mathematica 2.2
- To: mathgroup at smc.vnet.net
- Subject: [mg12810] Re: [mg12777] Split in Mathematica 2.2
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Fri, 12 Jun 1998 04:05:40 -0400
- Sender: owner-wri-mathgroup at wolfram.com
>At 12:04 AM -0700 1998.06.10, Andrzej Kozlowski wrote: >>.. Can anyone suggest a really fast implementation >>of Split that works in version 2.2? > >Here's an emulated Split with speed considerations. Basically, it iterates >through the list, mark down where the boundaries should be, then map Take >to the boundary indexes to obtain the new list. > >split::"usage"= > "split simulates the version 3 build-in function Split. Example: >Split[{1,2,3,4,4,3,2}]"; > >split[li_,fQ_:SameQ]:=Module[{liLength,index,i},liLength=Length at li; >index={};For[i=1,i<liLength,i++, > If[Not@(fQ@@Part[li,{i,i+1}]),index={index,i}]]; >(Take[li,#]&)/@(Transpose[{Flatten[{1,#+1}],Flatten[{#,liLength}]}]&)@ > Flatten at index]; > > >PS for those wondering what happened to my series of Mathematica expositions... I >got extremely busy with work. I will come back to it sometimes in the >future. > > Xah, xah at best.com > http://www.best.com/~xah/PageTwo_dir/more.html > "Perl: all unix's stupidity in one." Thanks. This is indeed pretty fast. Not as fast as the built-in Split but much faster than my simple version. w = Table[Random[Integer], {10000}]; using built-in Split: Split[w];//Timing Out[7]= {0.433333 Second,Null} Using Xah's split: In[6]:= split[w];//Timing Out[6]= {1.26667 Second,Null} Unfortunatelly procedural programming seems to triumph again... Andrzej Dr. Andrzej Kozlowski Professor of Mathematics Toyama International University Toyama, JAPAN http://sigma.tuins.ac.jp/