# Looping with “Table” over two variables

so essentially, I have a table:

table= Table[0, {5}, {30}, {6}];


I have now been trying to loop the functions below over level 2, (30) of the table and then looping it over dimension 3, (6).

I have gotten the loop over dimension 2 to work:

a=Flatten[Position[Transpose[table],
Min[Table[Max[Transpose[table][[p]]], {p, 1, 30}]]]][[1]]


This gives me the minimax of dimension 2 of the data. What I am failing at is looping this over dimension 3 also, ultimately producing a list of six different values in a.

Closest in my mind would be something like:

a=Table[Flatten[
Position[Transpose[teststat],
Min[Table[Max[Transpose[teststat][[n]][[i]]], {n, 1, 30}]]]], {i,
1, 6}];


but this is clearly wrong.

The first line of input data would be: {2.95095, 0.186768, 0.10373, 0.0430614, 0.13822, 0.0535124}, total data is this x30 x5.

Expected output would be something like: {2,3,7,22,11,44} I suppose my question can be reduced to: where do I have to place the second variable definition [[i]] and {i,1,6}

Context is: the table contains test statistics of 6 different model variations for the top 30 percentiles of data with 5 implicates. Within the percentiles I want to find the position of the value which minimizes the maximum of the test-statistics, for everyone of the six model variations.

Thank you for any and all suggestions. B

• The first line of input data would be: {2.95095, 0.186768, 0.10373, 0.0430614, 0.13822, 0.0535124}, total data is this x30 x5. – Ben.F Apr 13 '17 at 6:46
• Expected output something like: {2,3,7,22,11,44} – Ben.F Apr 13 '17 at 6:46
• Is the input example sufficient? I tried to copy and paste one of the first five dimensions, but the word limit. – Ben.F Apr 13 '17 at 6:48
• The point is, I think it is not clear what exactly you want to do so a description of your procedure would be on topic. It is clearly more than just looping. Also, the emphasis was on minimal. p.s. Function[arr, Position[arr, Min[Max /@ Transpose@arr]]] /@ table? – Kuba Apr 13 '17 at 7:13
• I suppose my question can be reduced to: where do I have to place the second variable definition [[i]] and {i,1,6}. – Ben.F Apr 13 '17 at 8:14

I guess you can create a function such as this:

minimax[table_] :=
Module[{slices, val, pos = {}},
slices = table[[All, All, #]] & /@ Range[Last@Dimensions@table];
val = Min@Max@slices[[#]] & /@ Range[Last@Dimensions@table];
pos = Position[slices[[#]], val[[#]]] & /@
Range[Last@Dimensions@table]
]


Then just run the

minimax[t] where t where t is your table.

EDIT: This way you will get the positions in the second level of your table.

EDIT2: cleared up the code this will give you pairs of indices, of the first two levels

• Thats great, thank you very much! I was thinking of a way easier solution all this time tho, like you mentioned in the comment above: to just iterate over the second parameter. Thats at least what i was trying to get to work but I just couldnt figure out placement etc. – Ben.F Apr 13 '17 at 14:27
• Actually looking at my code .... I did a horrible job. You can do the same simply by Min@Max@table[All,All,#]&/@Range[Last@Dimensions@table] – Vahagn Tumanyan Apr 13 '17 at 14:29
• Hmm, I just ran it, and it works great. However, it gives me the values, rather than the positions somewhere out of 1-30. Thats why I was using position before. Do you know what I mean? – Ben.F Apr 13 '17 at 14:31
• Yes, I see This gets the values, I will edit the answer to give the positions too. – Vahagn Tumanyan Apr 13 '17 at 14:32
• See the update, or alternatively the oneliner in this comment section can be modified too to be basically Position[Min@Max@table[All,All,#],table[All,All,#]]&/@Range[Last@Dimensions@table] – Vahagn Tumanyan Apr 13 '17 at 14:41