if (requireNamespace("abind", quietly = TRUE)) {
# load a 3d tensor representing an rgb image
x <- get(data("einops_image"))[1, , , ]
# Rearrange dimensions
einop(x, "h w c -> c h w")
# Reduce dimensions
einop(x, "h w c -> h w", "mean")
# Repeat dimensions
einop(x[, , 1], "h w -> h w c", c = 3)
}
Run the code above in your browser using DataLab