Finds the maximum of array elements along the specified axes.
Arguments
- x
(
arrayish)
One input. Can be any data type. An R value materializes at its default data type.- axes
(
integer()|NULL)
Axes to reduce over. Negative values count from the end, i.e.-1refers to the last axis. IfNULL(default), reduces over all axes.- drop
(
logical(1))
Whether to drop the reduced axes: removed from the output shape ifTRUE, set to 1 ifFALSE.- nan_rm
(
logical(1))
How to handleNaNvalues in float inputs. IfFALSE(default),NaNpropagates. IfTRUE,NaNvalues are skipped.
Value
(arrayish)
Has the input's data type. The shape is the input's with the reduced axes
removed (drop = TRUE) or set to 1 (drop = FALSE).
The max() generic
max() reduces over all axes and, like base::max(), takes several data
arguments: max(x, y) is the largest element of both arrays. na.rm
becomes nan_rm. Beyond base R, named arguments are passed on, so
max(x, axes = 1L) reduces a single axis – but only when x is the only
data argument.
See also
prim_reduce_max() for the underlying primitive.
Examples
x <- nv_matrix(1:6, nrow = 2)
# no axes given: reduce over all of them
nv_reduce_max(x)
#> AnvlArray
#> 6
#> [ CPUi32{} ]
# reducing axis 1 removes it, drop = FALSE keeps it at size 1
nv_reduce_max(x, axes = 1L)
#> AnvlArray
#> 2
#> 4
#> 6
#> [ CPUi32{3} ]
nv_reduce_max(x, axes = 1L, drop = FALSE)
#> AnvlArray
#> 2 4 6
#> [ CPUi32{1,3} ]
# negative axes count from the end
nv_reduce_max(x, axes = -1L)
#> AnvlArray
#> 5
#> 6
#> [ CPUi32{2} ]
# NaN propagates unless nan_rm = TRUE
nv_reduce_max(nv_array(c(1, NaN, 3)))
#> AnvlArray
#> nan
#> [ CPUf32{} ]
nv_reduce_max(nv_array(c(1, NaN, 3)), nan_rm = TRUE)
#> AnvlArray
#> 3
#> [ CPUf32{} ]