How to find a max point from discrete data of function?

I have a lot of points like $\{\{x_1,y_1,z_1\},\{x_2,y_2,z_2\},...,\{x_n,y_n,z_n\}\}$ which obtained by a function $z=f[x,y]$, and I want to find the max point of $z$, say $z_i$, and return the point coordinents $\{x_i,y_i,z_i\}$.

How do I do? I have checked the help, but find there is no function can return the point coordinents from a list.

2 Answers

data = RandomInteger[10, {10, 3}]

(*
{{6, 10, 0}, {0, 0, 8}, {6, 1, 1}, {2, 9, 6}, {4, 2, 9}, {8, 1, 10},
{4, 6, 9}, {5, 4, 1}, {9, 5, 6}, {1, 4, 4}}
*)

Select[data, #[[3]] == Max[data[[All, 3]]] &]

(* {{8, 1, 10}} *)


You can also use something like:

data[[Ordering[data[[All, 3]], -1]]]


This will return the largest z tuple, but only one if there are multiple tuples with same maximum z (in that case, using say -2 in place of -1 returns two of them, if there is only one max, using -2 would return the two tuples with the two largest z, etc.)

Finally, Cases can be used to same effect as select:

Cases[data, {x_, y_, z_} /; z == Max[data[[All, 3]]]]


If i understand your question correctly, one answer could be like this:

row = Position[data, Max[data[[;; , 3]]]][[1, 1]]
data[[row]]