Description Usage Arguments Value See Also Examples
rray_sum()
computes the sum along a given axis or axes. The dimensionality
of x
is retained in the result.
1 |
x |
A vector, matrix, or array to reduce. |
axes |
An integer vector specifying the axes to reduce over. |
The result of the reduction as a double with the same shape as x
, except
along axes
, which have been reduced to size 1.
Other reducers: rray_max
,
rray_mean
, rray_min
,
rray_prod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | x <- rray(1:10, c(5, 2))
# Reduce the number of rows to 1,
# summing along the way
rray_sum(x, 1)
# Reduce the number of columns to 1,
# summing along the way
rray_sum(x, 2)
# Reduce along all axes, but keep dimensions
rray_sum(x)
# Column-wise proportions
x / rray_sum(x, 1)
# Row-wise proportions
x / rray_sum(x, 2)
# Reducing over multiple axes
# This reduces over the rows and columns
# of each mini-matrix in the 3rd dimension
y <- rray(1:24, c(2, 3, 4))
rray_sum(y, c(1, 2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.