rray_prod() computes the product along a given axis or axes. The dimensionality of x is retained in the result.

rray_prod(x, axes = NULL)

Arguments

x

A vector, matrix, or array to reduce.

axes

An integer vector specifying the axes to reduce over. 1 reduces the number of rows to 1, performing the reduction along the way. 2 does the same, but with the columns, and so on for higher dimensions. The default reduces along all axes.

Value

The result of the reduction as a double with the same shape as x, except along axes, which have been reduced to size 1.

See also

Other reducers: rray_max, rray_mean, rray_min, rray_sum

Examples

x <- rray(1:10, c(5, 2)) rray_prod(x)
#> <rray<dbl>[,1][1]> #> [,1] #> [1,] 3628800
rray_prod(x, 1)
#> <rray<dbl>[,2][1]> #> [,1] [,2] #> [1,] 120 30240
rray_prod(x, 2)
#> <rray<dbl>[,1][5]> #> [,1] #> [1,] 6 #> [2,] 14 #> [3,] 24 #> [4,] 36 #> [5,] 50