MathGroup Archive 1999

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

Search the Archive

Re: Element extraction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg19604] Re: Element extraction
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 4 Sep 1999 21:09:13 -0400
  • References: <7qqau1$4c5@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mark Lawrence Storch <mscc+ at andrew.cmu.edu> wrote in message
news:7qqau1$4c5 at smc.vnet.net...
> Hello,
>     I am having a bit of trouble trying to extract elements out of
> nested lists.  I have an X x Y array where each element of the array is
> a 3x3 matrix.  I am trying to make density plots of each component.  For
> example, I would like to plot the 1,1 components of each element of the
> larger array.  I have tried the following:
>
> Array[g[[i,j][[a,b]],{i,Dimensions[g][[1]]},{j,Dimensions[g][[2]]}]
>
> where I am trying to get the a,b component
>
> This does not work, and I am not seeing exactly why not.  I am hoping
> someone can point out my error or suggest a way to extract the lists I
> need.
>
> Thank you,
> Mark Storch
> Carnegie Mellon University
> Department of Materials Science
>

Mark,
One way:

data = Array[a, {2, 2, 2, 2}]

    {{{{a[1, 1, 1, 1], a[1, 1, 1, 2]}, {a[1, 1, 2, 1],
        a[1, 1, 2, 2]}}, {{a[1, 2, 1, 1], a[1, 2, 1, 2]}, {a[1, 2, 2, 1],
        a[1, 2, 2, 2]}}}, {{{a[2, 1, 1, 1], a[2, 1, 1, 2]}, {a[2, 1, 2, 1],
        a[2, 1, 2, 2]}}, {{a[2, 2, 1, 1], a[2, 2, 1, 2]}, {a[2, 2, 2, 1],
        a[2, 2, 2, 2]}}}}


Map[#[[1, 1]] &, data, {2}]

    {{a[1, 1, 1, 1], a[1, 2, 1, 1]}, {a[2, 1, 1, 1], a[2, 2, 1, 1]}}


Map[#[[2, 1]] &, data, {2}]

    {{a[1, 1, 2, 1], a[1, 2, 2, 1]}, {a[2, 1, 2, 1], a[2, 2, 2, 1]}}


Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565




  • Prev by Date: Re: Question about evaluation with Sum
  • Next by Date: Re: in center of a triangle
  • Previous by thread: Re: Element extraction
  • Next by thread: axes in ListPlot