1
$\begingroup$

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

$\endgroup$
8
  • $\begingroup$ 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. $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 6:46
  • $\begingroup$ Expected output something like: {2,3,7,22,11,44} $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 6:46
  • $\begingroup$ Is the input example sufficient? I tried to copy and paste one of the first five dimensions, but the word limit. $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 6:48
  • $\begingroup$ 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? $\endgroup$
    – Kuba
    Commented Apr 13, 2017 at 7:13
  • $\begingroup$ I suppose my question can be reduced to: where do I have to place the second variable definition [[i]] and {i,1,6}. $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 8:14

1 Answer 1

1
$\begingroup$

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

$\endgroup$
10
  • $\begingroup$ 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. $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 14:27
  • 1
    $\begingroup$ 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] $\endgroup$ Commented Apr 13, 2017 at 14:29
  • 1
    $\begingroup$ 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? $\endgroup$
    – Ben.F
    Commented Apr 13, 2017 at 14:31
  • 1
    $\begingroup$ Yes, I see This gets the values, I will edit the answer to give the positions too. $\endgroup$ Commented Apr 13, 2017 at 14:32
  • 1
    $\begingroup$ 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] $\endgroup$ Commented Apr 13, 2017 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.