Sums array elements along the specified dimensions.
Arguments
- operand
(
arrayish)
Operand.- dims
(
integer()|NULL)
Dimensions to reduce. IfNULL(default), reduces over all dimensions, returning a scalar.- drop
(
logical(1))
Whether to drop reduced dimensions.- nan_rm
(
logical(1))
How to handleNaNvalues in floating-point inputs. IfFALSE(default),NaNpropagates. IfTRUE,NaNvalues are skipped.
Value
arrayish
Has the same data type as the input.
When drop = TRUE, the reduced dimensions are removed.
When drop = FALSE, the reduced dimensions are set to 1.
See also
prim_reduce_sum() for the underlying primitive.
Examples
x <- nv_matrix(1:6, nrow = 2)
nv_reduce_sum(x) # all dims -> scalar
#> AnvlArray
#> 21
#> [ CPUi32{} ]
nv_reduce_sum(x, dims = 1L)
#> AnvlArray
#> 3
#> 7
#> 11
#> [ CPUi32{3} ]
nv_reduce_sum(nv_array(c(1, NaN, 3)))
#> AnvlArray
#> nan
#> [ CPUf32{} ]
nv_reduce_sum(nv_array(c(1, NaN, 3)), nan_rm = TRUE)
#> AnvlArray
#> 4
#> [ CPUf32{} ]