julia

How to get minimal value of Array in Julia?


How do I get the minimum value of an Array, Vector, or Matrix in Julia?

The code min([1, 2, 3]) doesn't work.


Solution

  • The Julia manual: https://docs.julialang.org/en/v1/base/math/#Base.min

    https://docs.julialang.org/en/v1/base/collections/#Base.minimum

    min(x, y, ...)

    Return the minimum of the arguments. Operates elementwise over arrays.

    julia> min([1, 2, 3]...)
    1
    
    julia> min(2,3)
    2
    

    minimum(A, dims)

    Compute the minimum value of an array over the given dimensions.

    minimum!(r, A)

    Compute the minimum value of A over the singleton dimensions of r, and write results to r.

    julia> minimum([1, 2, 3])
    1