MathGroup Archive 2010

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

Search the Archive

Re: Nested list data extraction bottleneck

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107617] Re: Nested list data extraction bottleneck
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Fri, 19 Feb 2010 07:33:16 -0500 (EST)
  • References: <hllidp$q6$1@smc.vnet.net>

Am 19.02.2010 09:34, schrieb Mumtaz:
> (* 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 *)

As usual the question is what would qualify a solution to be better?
Your code works, so it is good. Here are two approaches that are shorter
(1) and should be faster (2), but probably are also more arcane:

Map[Last, LS, -2]

Flatten[LS[[All, All, -1, -1]]]

> (* 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}} *)

the above need only small changes:

Map[Last, LS, {-2}]

LS[[All, All, All, -1]]

search for the documentation of Map to learn about the optional third
argument, but I think when you know the depth of your lists in advance
nothing will beat the part specifications...

hth,

albert





  • Prev by Date: Re: Nested list data extraction bottleneck
  • Next by Date: Re: NDsolve with a quasi random scource
  • Previous by thread: Re: Nested list data extraction bottleneck
  • Next by thread: Re: Re: Re: May we trust IntegerQ