Computes the arithmetic mean along the specified axes. You can also
use mean().
Usage
nv_mean(x, axes = NULL, drop = TRUE, nan_rm = FALSE)
# S3 method for class 'AnvlArray'
mean(x, trim = 0, na.rm = FALSE, ..., axes = NULL, drop = TRUE)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.- trim
Currently not supported.
- na.rm
Forwarded to
nv_mean()'snan_rmargument.- ...
No additional arguments.
Value
(arrayish)
Has the input's data type where that is a float, and the default float
data type (see default_dtypes())
otherwise. The shape is the input's with the reduced axes removed (drop = TRUE) or set to 1 (drop = FALSE).
Examples
x <- nv_matrix(1:6, nrow = 2)
# an integer input is averaged at the default float data type
nv_mean(x)
#> AnvlArray
#> 3.5000
#> [ CPUf32{} ]
# a float input keeps its own, whatever the default float is
nv_mean(nv_array(c(1, 2), dtype = "f64"))
#> AnvlArray
#> 1.5000
#> [ CPUf64{} ]
# reducing axis 1 removes it, drop = FALSE keeps it at size 1
nv_mean(x, axes = 1L)
#> AnvlArray
#> 1.5000
#> 3.5000
#> 5.5000
#> [ CPUf32{3} ]
nv_mean(x, axes = 1L, drop = FALSE)
#> AnvlArray
#> 1.5000 3.5000 5.5000
#> [ CPUf32{1,3} ]
# NaN propagates unless nan_rm = TRUE
nv_mean(nv_array(c(1, NaN, 3)))
#> AnvlArray
#> nan
#> [ CPUf32{} ]
nv_mean(nv_array(c(1, NaN, 3)), nan_rm = TRUE)
#> AnvlArray
#> 2
#> [ CPUf32{} ]