Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6625 > unrolled thread

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

Started byGy Peng <hitphyopt@gmail.com>
First post2011-11-22 10:44 +0000
Last post2011-11-23 12:17 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to get sub-list elements at certain position in a long list Gy Peng <hitphyopt@gmail.com> - 2011-11-22 10:44 +0000
    Re: How to get sub-list elements at certain position in a long list Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-11-23 12:10 +0000
    Re: How to get sub-list elements at certain position in a long list "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-23 12:02 +0000
    Re: How to get sub-list elements at certain position in a long list Ray Koopman <koopman@sfu.ca> - 2011-11-23 12:17 +0000

#6625 — How to get sub-list elements at certain position in a long list

FromGy Peng <hitphyopt@gmail.com>
Date2011-11-22 10:44 +0000
SubjectHow to get sub-list elements at certain position in a long list
Message-ID<jafuf7$rs7$1@smc.vnet.net>
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!!!
*
*

[toc] | [next] | [standalone]


#6642

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-11-23 12:10 +0000
Message-ID<jainqt$ene$1@smc.vnet.net>
In reply to#6625
On Nov 22, 9:44 pm, Gy Peng <hitphy...@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!!!
> *
> *

It is best to use Part for this. I am assuming that the asterisks are
a legacy of a cut and paste?

yourList = {{{{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}}}}

yourList[[All, All, -1]]

or

Flatten[yourList[[All, All, -1]], 1]

Mike

[toc] | [prev] | [next] | [standalone]


#6647

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2011-11-23 12:02 +0000
Message-ID<jainde$eea$1@smc.vnet.net>
In reply to#6625
On Tue, 22 Nov 2011 10:44:55 -0000, Gy Peng <hitphyopt@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!!!
> *
> *

I'm not sure where all the superfluous *'s have come from, but these  
render your expression syntactically invalid, so I have removed them.

lst = {{
  {{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}}
}}

You can use Part:

lst[[All, All, 4]]

{{{-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}}}

Or, if you insist on a solution with Map,

Map[#[[4]] &, lst, {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}}}

[toc] | [prev] | [next] | [standalone]


#6664

FromRay Koopman <koopman@sfu.ca>
Date2011-11-23 12:17 +0000
Message-ID<jaio8a$eq8$1@smc.vnet.net>
In reply to#6625
On Nov 22, 2:44 am, Gy Peng <hitphy...@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!!!
> *
> *

Flatten[data[[All,All,4]],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}}

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web