data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, Norm@# &]
Output: {{2, 2}}
When applying numerically :
data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, N@Norm@# &]
Output: {{1, 2}}
data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, Norm@# &]
Output: {{2, 2}}
When applying numerically :
data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, N@Norm@# &]
Output: {{1, 2}}
TakeSmallestBy gives the correct solution automatically
TakeSmallestBy[data, Norm, 1]
{{1, 2}}
A hash-free MinimalBy solution
MinimalBy[data, N @* Norm]
{{1, 2}}
Documentation Details of TakeSmallestBy
"TakeSmallestBy sorts ... by numerical magnitude."
Documentation Details of MinimalBy
"Values ... are compared using the same canonical order as in Sort."
Norm /@ data // Sort
{2 * Sqrt[2], 3 * Sqrt[2], Sqrt[5]}
N[%]
{2.82843, 4.24264, 2.23607}
Norm doesn't give the correct answer (see @Nasser's answer).
workaround
data = {{1, 2}, {2, 2}, {3, 3}};
MinimalBy[data, ( # . # &)]
(*{{1, 2}}*)
MinimalBy: Values of $f[e_i]$ are compared using the same canonical order as inSort. – xzczd Mar 11 '24 at 10:13