Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: How to get sub-list elements at certain position in a long list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123113] Re: How to get sub-list elements at certain position in a long list
  • From: Bob Hanlon <hanlonr357 at gmail.com>
  • Date: Wed, 23 Nov 2011 07:09:33 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

I don't understand your data (presence of * and **), your description,
or your stated desired result given the data. However, these may be
close to what you want.

data = {{{{2.5}, {3.8, 31}, {54.23, 46.263, 45.987}, {-82.1476,
      5.17782, -205.36}}, {{2.5}, {4.2, 30}, {233.835, 46.469,
      46.819}, {93.8625, -13.9818, -198.778}}}, {{{2.5}, {4.1, 30}, {139.845,
      15.719, 155.87}, {93.6633, 4.46398, -205.432}}, {{2.5}, {2.6,
      32}, {113.381, 40.988, 85.09}, {90.1206,
      16.9792, -205.314}}}, {{{2.5}, {3.1, 30}, {113.858, 34.709,
      87.567}, {55.3298, 17.7214, -211.648}}, {{2.5}, {2.7, 30}, {110.54,
      31.595, 85.601}, {-25.8558, 175.588, -121.105}}}};

Last /@ Flatten[data, 1]

{{-82.1476, 5.17782, -205.36}, {93.8625, -13.9818, -198.778}, {93.6633,
  4.46398, -205.432}, {90.1206, 16.9792, -205.314}, {55.3298,
  17.7214, -211.648}, {-25.8558, 175.588, -121.105}}

Flatten[data[[All, All, -1]], 1]

{{-82.1476, 5.17782, -205.36}, {93.8625, -13.9818, -198.778}, {93.6633,
  4.46398, -205.432}, {90.1206, 16.9792, -205.314}, {55.3298,
  17.7214, -211.648}, {-25.8558, 175.588, -121.105}}

Flatten[Map[Last, data, {2}], 1]

{{-82.1476, 5.17782, -205.36}, {93.8625, -13.9818, -198.778}, {93.6633,
  4.46398, -205.432}, {90.1206, 16.9792, -205.314}, {55.3298,
  17.7214, -211.648}, {-25.8558, 175.588, -121.105}}

Cases[data, {__List, x_List} -> x, {2}]

{{-82.1476, 5.17782, -205.36}, {93.8625, -13.9818, -198.778}, {93.6633,
  4.46398, -205.432}, {90.1206, 16.9792, -205.314}, {55.3298,
  17.7214, -211.648}, {-25.8558, 175.588, -121.105}}

% == %% == %%% == %%%%

True


Bob Hanlon


On Tue, Nov 22, 2011 at 5:36 AM, Gy Peng <hitphyopt at gmail.com> wrote:
> Dear Experts,
>
> I have a list:
>
> {{{{2.5}, {3.8, 31}, {54.23, 46.263, 45.987}, *{-82.1476,** 5.17782,
> -205.36}*}, {{2.5}, {4.2, 30}, {233.835, 46.469,
>    46.819}, *{93.8625, -13.9818, -198.778}*}}, {{{2.5}, {4.1,30},
> {139.845, 15.719, 155.87}, *{93.6633,**4.46398, -205.432}*}, {{2.5}, {2.6,
> 32}, {113.381, 40.988,85.09}, *{90.1206, 16.9792, -205.314}*}}, {{{2.5},
> {3.1,30}, {113.858, 34.709, 87.567}, *{55.3298,**17.7214, -211.648}*},
> {{2.5}, {2.7, 30}, {110.54, 31.595,85.601}, *{-25.8558, 175.588, -121.105}*
> }}}
>
> How do I get each 4th sublist element in the last level? I mean, I want to
> get a list looks like:
> {*{-82.1476, **5.17782, -205.36}, **{93.8625, -13.9818, -198.778},**{90.1206,
> 16.9792, -205.314},**{55.3298,**17.7214, -211.648},**{-25.8558, 175.588,
> -121.105}}*
> which only includes every 4th element in the last level. Do I describe my
> question clearly?
>
> Better not to use any "For", simple Map or Thread method are preferred.
>
> Thank you very much!!!
> *



  • Prev by Date: Re: special character size
  • Next by Date: Re: How to get sub-list elements at certain position in a long list
  • Previous by thread: Re: How to get sub-list elements at certain position in a long list
  • Next by thread: Re: How to get sub-list elements at certain position in a long list