Computes the standard deviation 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.- correction
(
integer(1))
Degrees of freedom correction. Default is1(Bessel's correction).- 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 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).
Details
Uses Bessel's correction by default (correction = 1), matching R's sd().
Set correction = 0 for population standard deviation.
Examples
x <- nv_array(1:5)
# the result is a float, even though the input is an integer
nv_sd(x)
#> AnvlArray
#> 1.5811
#> [ CPUf32{} ]
# Bessel's correction by default, correction = 0 for the population value
nv_sd(x, correction = 0L)
#> AnvlArray
#> 1.4142
#> [ CPUf32{} ]