# Specify a 3D array, where array elements contain other kind of variables?

**URL:** <https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657>\
**Category:** Questions\
**Created:** [June 26, 2018, 2:03pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657 "2018-06-26T14:03:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilicza](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gilicza](https://community.wolfram.com/u/gilicza)\
**Post date:** [June 26, 2018, 2:03pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/1 "2018-06-26T14:03:11Z")

</div>

Dear Community,

In Fortran I can easily specify a 3D array, where array elements contain other kind of variables(real, integer, logical, vector, etc) This is very effivcient and conveniet. An example is below:

```
GBLOCK( 88 , 21 , 12 ).BO = 1.22 (real) ;
GBLOCK( 88 , 21 , 12 ).KRO = 0.7 (real) ;
GBLOCK( 88 , 21 , 12 ).ACTIVE = .TRUE. (logical) ;
GBLOCK( 88 , 21 , 12 ).CT(2) = 55.7 (vector, real) ;
GBLOCK( 88 , 21 , 12 ).CT(4) = 19.2 (vector, real) ;
GBLOCK( 88 , 21 , 12 ).IBLOCK = 43561 (integer) ;

```

My question is, how could I specify a similar structure in Mathematica? What would be the equivalent of the above array in Mathematica?

Tx for the kind help in advance,  
best regards  
Andras

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [June 26, 2018, 4:39pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/2 "2018-06-26T16:39:52Z")

</div>

There’s no requirement that the members of a Mathematica list be of the same type

```
In[1]:= ar = {1, 0.3, "test", \[Pi], 1 + I, \[Infinity]}

Out[1]= {1, 0.3, "test", \[Pi], 1 + I, \[Infinity]}

```

---

<div class="post-metadata">

**Author:** ![anon\_91240867](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_91240867](https://community.wolfram.com/u/anon_91240867)\
**Post date:** [July 4, 2018, 3:32am UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/3 "2018-07-04T03:32:43Z")

</div>

Head[x] → Symbol

Head[“the”] → String

Head[7] → …

as the last poster said, mathematica List[{a,b,c}] or Array[?], you do not need to worry about mixing types

furthermore, arrays in Mathematica are associative

```
Ar["the"]:=1
Ar["that"]:="there"
Ar["that"]:=Ar["the"]

```

all that works, and we expect if there are many strings for indicies we expect mathematica employs at least a binary search to cross reference the value

---

<div class="post-metadata">

**Author:** ![gilicza](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gilicza](https://community.wolfram.com/u/gilicza)\
**Post date:** [July 12, 2018, 4:08pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/4 "2018-07-12T16:08:46Z")

</div>

Tx for the contributions.

I have finally found an easy way to do it. One possible solution is in the attached notebook.

cheers,  
Andras

[ThreeDArray.nb](https://community.wolfram.com/uploads/short-url/6vRkkUezyNTH1B83LTqIHv3vIdM.nb) (9.12 KB)

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [July 12, 2018, 4:28pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/5 "2018-07-12T16:28:40Z")

</div>

Andras,

I think you are overcomplicating things. As Frank pointed out, you can automatically put different types in an array.

You can just put whatever you want in the array and reference individual elements:

```
In[20]:= var = {{18, False, 12.2}, {23.111, True, 34.11}}

Out[20]= {{18, False, 12.2}, {23.111, True, 34.11}}

In[21]:= var[[2]]

Out[21]= {23.111, True, 34.11}

In[23]:= var[[2, 1]] = 24;

In[18]:= var[[2]]

Out[18]= {24, True, 34.11}

```

I do not understand why you need all that indirect referencing. Maybe I am missing something.

Regards,

Neil

---

<div class="post-metadata">

**Author:** ![gilicza](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gilicza](https://community.wolfram.com/u/gilicza)\
**Post date:** [July 12, 2018, 5:17pm UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/6 "2018-07-12T17:17:30Z")

</div>

I need this indirect referencing because then I do not have to keep in mind in which position an element in the list is. E.g. activeind = 3 , so I can referrence an active / inactive 3D grid property easily by gblock[[j, i, k, activeind]] = True (or False) . (The Dollar sign was removed from activeind.) I’m actually transfering an older Fortran code of mine into the Wolfram Language, and this seemed to me the easiest way to do it. In Fortran I do the same this way:

GBLOCK(J,I,K).ACTIVE = .TRUE. (or .FALSE.)

If there is a more efficient way, I would be gratefuly to learn it.

Tx, Andras

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [July 13, 2018, 10:00am UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/7 "2018-07-13T10:00:08Z")

</div>

As an alternative you could make an array of associations. And use the associations keys to access the elements.  
In the attachment I have made an adaption of your notebook.

[ThreeDArrayOfAssociations.nb](https://community.wolfram.com/uploads/short-url/kRJB2aYJgapiA0UWhrRw4XLrNYK.nb) (10.2 KB)

---

<div class="post-metadata">

**Author:** ![gilicza](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gilicza](https://community.wolfram.com/u/gilicza)\
**Post date:** [July 13, 2018, 10:59am UTC](https://community.wolfram.com/t/specify-a-3d-array-where-array-elements-contain-other-kind-of-variables/12657/8 "2018-07-13T10:59:21Z")

</div>

Dear Hans,

Very elegant, thank you very much!

best regards

Andras
