Today I explore argmax
and argmin
function defined in Base
package.
armax
returns a maximal index, while argmin
returns a minimal index.
A = [1 2; 3 4]
argmax(A)
Output:
CartesianIndex(2, 2)
B=[-1 2; 10 -10]
argmax(B)
Output:
CartesianIndex(2, 1)
argmin(B)
Output:
CartesianIndex(2, 2)
argmax
can have a function as the first argument (say f
) and the domain of the function (say x
) as the second argument and it will still find a value of x
that maximizes f(x)
.
plot(x->x^2-3*x, -10:10)
Output:
argmax(x->x^2-3*x,-10:10 )
argmin(x->x^2-3*x,-10:10 )
Output:
-10
1