# NOT RUN {
x <- matrix(1:8, ncol = 2)
# Split the rows
# (4, 2) -> (1, 2)
rray_split(x, 1)
# Split the columns
# (4, 2) -> (4, 1)
rray_split(x, 2)
# Split along multiple dimensions
# (4, 2) -> (1, 1)
rray_split(x, c(1, 2))
# The above split is the default behavior
rray_split(x)
# You can technically split with a size 0 `axes`
# argument, which essentially requests no axes
# to be split and is the same as `list(x)`
rray_split(x, axes = integer(0))
# ---------------------------------------------------------------------------
# 4 dimensional example
x_4d <- rray(
x = 1:16,
dim = c(2, 2, 2, 2),
dim_names = list(
c("r1", "r2"),
c("c1", "c2"),
c("d1", "d2"),
c("e1", "e2")
)
)
# Split along the 1st dimension (rows)
# (2, 2, 2, 2) -> (1, 2, 2, 2)
rray_split(x_4d, 1)
# Split along columns
# (2, 2, 2, 2) -> (2, 1, 2, 2)
rray_split(x_4d, 2)
# Probably the most useful thing you might do
# is use this to split the 4D array into a set
# of 4 2D matrices.
rray_split(x_4d, c(3, 4))
# }
Run the code above in your browser using DataLab