Sums over the specified dimensions of an n-dimensional array and reshapes the result back into an array with the correct dimensions.

array_sum(arr, keep_dims)

Arguments

arr

An n-dimensional array.

keep_dims

An integer vector specifying the dimensions to keep after the summation.

Value

An array with dimensions corresponding to `keep_dims`, containing the summed values.

Examples

arr <- array(1:24, dim = c(2, 3, 4))
result <- array_sum(arr, c(1, 2))