Re: Nested list data extraction bottleneck
- To: mathgroup at smc.vnet.net
- Subject: [mg107621] Re: [mg107601] Nested list data extraction bottleneck
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Fri, 19 Feb 2010 07:34:00 -0500 (EST)
- References: <201002190834.DAA00850@smc.vnet.net>
Hi, In[175]:= LS = {{{0, 533}, {0, 549}, {0, 554}, {0, 547}}, {{0, 533}, {0, 536}, {0, 541}, {0, 533}}}; The following is probably as fast as it gets: In[176]:= LS[[All, -1]] Out[176]= {{0, 547}, {0, 533}} In[177]:= LS[[All, -1, -1]] Out[177]= {547, 533} In[183]:= LS[[All, All, 2]] Out[183]= {{533, 549, 554, 547}, {533, 536, 541, 533}} If you deal with numbers (reals in particular), you may consider converting your lists to PackedArray form with Developer`ToPackedArray (if it is not already in that form) - this may speed up many operations on your data. Hope this helps. Regards, Leonid On Fri, Feb 19, 2010 at 11:34 AM, Mumtaz <x64x58 at gmail.com> wrote: > (* BEGIN the beguine simple code *) > > ClearAll["Global`*"] > > (* prototype data list *) > LS = {{{0,533},{0,549},{0,554},{0,547}},{{0,533},{0,536},{0,541}, > {0,533}}}; > > (* list LS dimensions *) > LSdim = Dimensions[LS] > {2,4,2} > > (* list LS terminal values -- major bottle neck for higher dimensions > *) > LSterminal = Table[Last[LS[[i]]], {i, LSdim[[3]]}] > {{0,547},{0,533}} > > (* extract relevant list LS terminal values data *) > LSterminal[[All,2]] > {547,533} > > (* OK *) > (* END simple code *) > > > (* No doubt, there is a better way to extract terminal values from > list LS since the data has already been generated; Table function for > generating LSterminal should not be necessary *) > > (* Any ideas appreciated *) > > (* Further, any ideas on extracting the following type stream from > list LS would also be appreciated: *) > (* SomeFunction[LS] operating on LS above will output: *) > (* {{533, 549, 554, 547}, {533, 536, 541, 533}} *) > > > > (* Thanks in advance and best regards, M *) > > (* PS Please note the 0 element in list LS is a result of rounding for > legibility. Parsing the list LS on that basis would not be optimal. > All numbers are Real *) > >
- References:
- Nested list data extraction bottleneck
- From: Mumtaz <x64x58@gmail.com>
- Nested list data extraction bottleneck