Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'dimensions' topicStudent Support Forum > General > "dimensions"

< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
07/11/13 1:07pm

In[1]:= mat = Table[RandomReal[], {2}, {3}, {4}]

Out[1]= {{
{0.409885, 0.169556, 0.329164, 0.323573},
{0.388686, 0.481326, 0.209454, 0.410088},
{0.587821, 0.496418, 0.368553, 0.92741}},
{{0.29089, 0.355713, 0.90572, 0.294108},
{0.32918, 0.758261, 0.418268, 0.338903},
{0.186673, 0.5106, 0.0750007, 0.892451}}}

In[2]:= dims = Dimensions[mat];
vars = {a, b, c, d, e, f, g, h, i, j, k, l};
varl = Take[vars, Length[Most[dims]]];
vardims = Transpose[{Take[vars, Length[Most[dims]]], Most[dims]}]

Out[5]= {{a, 2}, {b, 3}}

In[6]:= Flatten[Table[{
First[mat[[Sequence @@ varl]]],
Last[mat[[Sequence @@ varl]]],
Max[mat[[Sequence @@ varl]]],
Min[mat[[Sequence @@ varl]]]},
Evaluate[Sequence @@ vardims]], 1]

Out[6]= {
{0.409885, 0.323573, 0.409885, 0.169556},
{0.388686, 0.410088, 0.481326, 0.209454},
{0.587821, 0.92741, 0.92741, 0.368553},
{0.29089, 0.294108, 0.90572, 0.29089},
{0.32918, 0.338903, 0.758261, 0.32918},
{0.186673, 0.892451, 0.892451, 0.0750007}}

Or perhaps more simply

In[7]:= Map[{First[#], Last[#], Max[#], Min[#]} &, Level[mat, {-2}]]

Out[7]= {
{0.409885, 0.323573, 0.409885, 0.169556},
{0.388686, 0.410088, 0.481326, 0.209454},
{0.587821, 0.92741, 0.92741, 0.368553},
{0.29089, 0.294108, 0.90572, 0.29089},
{0.32918, 0.338903, 0.758261, 0.32918},
{0.186673, 0.892451, 0.892451, 0.0750007}}

URL: ,

Subject (listing for 'dimensions')
Author Date Posted
dimensions augustus 07/10/13 12:14pm
Re: dimensions Bill Simpson 07/11/13 1:07pm
Re: dimensions augustus 07/17/13 12:23pm
Re: Re: dimensions Bill Simpson 07/17/13 7:11pm
Re: Re: Re: dimensions augustus 07/23/13 4:19pm
Re: Re: Re: Re: dimensions Bill Simpson 07/25/13 11:02am
< Previous Comment | Next Comment >Help | Reply To Comment | Reply To Topic