Re: structure array equivalent in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg67207] Re: structure array equivalent in Mathematica
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 11 Jun 2006 23:08:41 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e6gdun\$ngj\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```kevin_jazz wrote:
> Like many people I imagine, I'm transitioning to Mathematica from a
> background in another system.
> One of the common data types is the structure array.  Let's say I have
> an observational data set that includes pressure, temperature, and
> water vapor as a function of altitude.  So, in pseudo-code I might
> define a structure as
>
> observation = {pressure: float(100), temperature: float(100),
> water_vapor: float(100)}
>
> I could then access the elements of this observation as
>
> observation.pressure
> observation.temperature, etc.
>
> Furthermore, I could aggregate these observations into a larger list, e.g.
> obs_day = {observation, observation, observation}
> to be accessed as
> obs_day[1].pressure for the first element (assuming 1-index).

Hi Kevin,

First, we create some random data. This is a list of list, 10 rows by 3
columns, that can be deemed as representing a 10 x 3 matrix of real
entries, or nested arrays.

In[3]:=
obsDay = Table[{Random[], Random[], Random[]}, {10}]

Out[3]=
{{0.733283, 0.7432, 0.449928},

{0.0446911, 0.277203, 0.780983},

{0.0453825, 0.412505, 0.0190734},

{0.497491, 0.0276473, 0.948924},

{0.924536, 0.803803, 0.969818},

{0.0614517, 0.335925, 0.462168},

{0.503749, 0.308574, 0.35449},

{0.763352, 0.312975, 0.0490268},

{0.621208, 0.0201513, 0.863047},

{0.00433568, 0.344004, 0.239168}}

Pressure recorded on the first observation of the day:

In[5]:=
obsDay[[1,1]]

Out[5]=
0.733283

Temperature recorded on the third observation of the day:

In[6]:=
obsDay[[3,2]]

Out[6]=
0.412505

The fifth record:

obsDay[[5,All]]

Out[7]=
{0.0453825, 0.412505, 0.0190734}

The fifth record again:

obsDay[[5]]

Out[8]=
{0.0453825, 0.412505, 0.0190734}

All the water_vapor recorded this day:

In[9]:=
obsDay[[All,3]]

Out[9]=
{0.449928, 0.780983, 0.0190734, 0.948924, 0.969818,

0.462168, 0.35449, 0.0490268, 0.863047, 0.239168}

> Now, the list in Mathematica is quite powerful and I think can be
> set-up in a similar fashion.
>
> So my question is how is the structure array commonly implemented in
> Mathematica or its equivalent?
>
> If there is a previous thread (I looked but didn't find any) on the
> topic or in the Mathematica book or Mathematica Journal that I missed,
> feel free to point me in that direction.

The Mathematica Book Online, A Practical Introduction to Mathematica,
Lists
http://documents.wolfram.com/mathematica/TheMathematicaBook/APracticalIntroductionToMathematica/Lists/index.en.html

The Mathematica Book Online, Part 2: Principles of Mathematica, Section
2.4: Manipulating Lists
http://documents.wolfram.com/mathematica/book/section-2.4

Built-in Functions, Lists and Matrices
http://documents.wolfram.com/mathematica/Built-inFunctions/ListsAndMatrices/

Built-in Functions /  Advanced Documentation /  Linear Algebra /  Linear
Algebra in Mathematica /  Performance /  Packed Arrays

>
> Many thanks,
>
> Kevin Bowman
> Jet Propulsion Laboratory
>

HTH,
Jean-Marc

```

• Prev by Date: Re: mg67144: 3rd try!
• Next by Date: Re: List manipulation question
• Previous by thread: Re: structure array equivalent in Mathematica
• Next by thread: Re: structure array equivalent in Mathematica