einops.repeat | R Documentation |
This operation includes functionality of repeat, tile, and broadcast functions.
einops.repeat(x, expr, ..., .row_major = getOption("einops_row_major", FALSE))
`repeat`(x, expr, ..., .row_major = getOption("einops_row_major", FALSE))
When composing axes, C-order enumeration is used (consecutive elements have different last axis). Find more examples in the vignettes.
tensor of the same type as input, with dimensions according to output pattern
repeat()
?repeat
is a reserved keyword in R that acts the same as
while(TRUE)
, and has no way of being overridden. Hence,
this function can only be called as einops.repeat()
or
using backticks as `repeat`()
.
if (requireNamespace("abind", quietly = TRUE)) {
set.seed(42)
# a grayscale image (of shape height x width)
image <- array(rnorm(30 * 40), dim = c(30, 40))
# change it to RGB format by repeating in each channel
output <- einops.repeat(image, 'h w -> h w c', c = 3)
# Visualize the output
as_image_tensor(output)
# repeat image 2 times along height (vertical axis)
output <- einops.repeat(image, 'h w -> (r h) w', r = 2)
# repeat image 2 times along height and 3 times along width
output <- einops.repeat(image, 'h w -> (h2 h) (w3 w)', h2 = 2, w3 = 3)
# convert each pixel to a small square 2x2, i.e. upsample an image by 2x
output <- einops.repeat(image, 'h w -> (h h2) (w w2)', h2 = 2, w2 = 2)
# 'pixelate' an image first by downsampling by 2x, then upsampling
downsampled <- reduce(image, '(h h2) (w w2) -> h w', 'mean', h2 = 2, w2 = 2)
output <- einops.repeat(downsampled, 'h w -> (h h2) (w w2)', h2 = 2, w2 = 2)
as_image_tensor(einops.repeat(output, 'h w -> h w 3'))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.