How to get minimal value of Array in Julia?
Asked Answered
A

2

25

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

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

Artur answered 30/3, 2016 at 9:5 Comment(1)
Use minimum, not min.Nucleoside
M
32

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
Martineau answered 30/3, 2016 at 10:16 Comment(6)
The answer to the original question is rather hidden in your answer. Certainly give a reference to the manual, but don't just copy it here.Nucleoside
And for completeness (and future readers) examples are good, for example, min([1,2],[3,0]) for elementwise min, etc.Equivocation
min([1,2],[3,0]) is deprecated. Now one should use min.([1,2],[3,0])Agora
The link in the answer is now dead. Correct link is docs.julialang.org/en/stable/stdlib/collectionsCauthen
The right link to the function minimum, as of 1.1, is currently docs.julialang.org/en/latest/base/collections/#Base.minimumMaus
All the links in the comments are dead now. (error 404)Indoiranian
T
0

To get the minimum of a vector, min() cannot be used but minimum() can

Tiebold answered 17/6 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.