max

max(x, y, ...)

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

Examples

  • Find the maximum of two numbers:

    julia> max(5, 10)
    10
  • Find the maximum of multiple numbers:

    julia> max(2, 4, 6, 8)
    8
  • Find the maximum among array elements:

    julia> arr = [5, 2, 9, 1, 7];
    julia> max(arr...)
    9
  • Find the maximum of elements in multiple arrays:

    julia> arr1 = [2, 4, 6];
    julia> arr2 = [1, 8, 3];
    julia> max(arr1..., arr2...)
    8
  • Find the maximum of a matrix along a specific axis:
    julia> matrix = [1 2 3; 4 5 6; 7 8 9];
    julia> max(matrix, dims=1)
    1×3 Array{Int64,2}:
    7  8  9

Common mistake example:

julia> max([1, 2, 3], [4, 5, 6, 7])
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")

In this example, the arrays have different lengths, causing a DimensionMismatch error when trying to find the maximum. Ensure that the arrays being compared have the same dimensions or are compatible for elementwise comparison.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: