# Pick the maximum element of each nested list [closed]

Suppose that I have a list with nested lists, where each nested list contain entries consisting in 3 columns:

t = RandomReal[{0, 10}, {60, 3}];

minx = 0;
maxx = 10;
miny = 0;
maxy = 10;
resx = 5;
resy = 5;
stepx = (maxx – minx)/resx;
stepy = (maxy – miny)/resy;
grid = Table[
Select[t,
minx + stepx*(i – 1) < #[[1]] <= minx + stepx* i && miny + stepy*(j - 1) < #[[2]] <= miny + stepy*j &], {i, 1, resx}, {j, 1, resy} ]; Map[MatrixForm, grid, {2}] // MatrixForm Now I want to generate an array of the same size, in this case 5×55\times 5 such that each entry contains the row with the maximum value of the third column of the third list. For instance, in this example such an array MyArray would have as elements: MyArray[[1,1]]= {1.94367, 1.96706, 5.63112} MyArray[[1,2]]= {0.706452, 3.92499, 4.00843} MyArray[[2,1]]= {3.44211, 1.23998, 8.72222} ... MyArray[[5,5]]= {9.78142, 8.02858, 4.28738} I know how to pick the maximum element of each sublist, using for instance for the first one: Pick[grid[[1, 1]], #, Max@#] &@grid[[1, 1]][[All, 3]] But I don't know how to apply it simultaneously to all the lists. I guess that is using Map somehow, but I cannot figure out how... Thanks! ================= ================= 2 Answers 2 ================= You just need to map your picking function at the second level of the grid pick[list_] := Pick[list, #, Max@#] &@list[[All, 3]] Map[pick, grid, {2}] data = Table[RandomReal[10, {RandomInteger[{3, 6}], 3}], {i, 3}, {j, 3}]; MatrixForm@Map[MatrixForm, data, {2}] flatter = Flatten[data, 1]; thirdcols = flatter[[All, All, 3]]; max = Max /@ thirdcols; rowspositions = Flatten@MapThread[Position, {thirdcols, max}]; extracts = Transpose[{Range[9], rowspositions}]; flatter[[Sequence @@ #]] & /@ extracts {{9.96146, 4.95039, 9.12134}, {5.0613, 7.55387, 7.6069}, {9.93072, 9.36066, 6.9762}, {5.37254, 5.64206, 7.42148}, {6.2932, 9.29207, 9.24816}, {6.75852, 0.38891, 9.56726}, {1.96899, 7.40202, 6.87286}, {8.00277, 5.72873, 8.91649}, {4.70735, 5.16466, 8.67289}}      This procedure doesn't work with the grid from the question. – Jack LaVigne Oct 9 '15 at 12:17      The OP changed the question after I posted my answer. – Chris Degnen Oct 9 '15 at 13:31