# NOT RUN {
x <- rray(1:16, c(2, 2, 2, 2))
# Selecting the first column
rray_slice(x, i = 1, axis = 2)
# rray_slice() is particularly useful for
# subsetting higher dimensions because you don't
# have to worry about the commas
rray_slice(x, i = 2, axis = 4)
# Compare the above with the equivalent using `[`
x[, , , 2]
# `i` can be a character vector if `x` has names along `axis`
x <- rray_set_axis_names(x, axis = 4, c("foo", "bar"))
rray_slice(x, "bar", axis = 4)
# The assignment variation can be useful
# for assigning to higher dimensional elements
rray_slice(x, 1, 3) <- matrix(c(99, 100), nrow = 1)
# }
Run the code above in your browser using DataLab