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.