Multiplies 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_prod() for the underlying primitive.
Examples
x <- nv_matrix(1:6, nrow = 2)
nv_reduce_prod(x) # all dims -> scalar
#> AnvlArray
#> 720
#> [ CPUi32{} ]
nv_reduce_prod(x, dims = 1L)
#> AnvlArray
#> 2
#> 12
#> 30
#> [ CPUi32{3} ]
nv_reduce_prod(nv_array(c(2, NaN, 3)))
#> AnvlArray
#> nan
#> [ CPUf32{} ]
nv_reduce_prod(nv_array(c(2, NaN, 3)), nan_rm = TRUE)
#> AnvlArray
#> 6
#> [ CPUf32{} ]