rray_set_dimensions: Set the dimensions of an array

View source: R/dimensions.R

rray_set_dimensionsR Documentation

Set the dimensions of an array

Description

rray_set_dimensions() sets the dimensions of x to a new set of dimensions without changing the total number of elements. Unlike rray_broadcast(), which repeats elements to fill new dimensions, rray_set_dimensions() simply reinterprets the existing elements under new dimensions without changing its size.

Usage

rray_set_dimensions(x, dimensions)

Arguments

x

An array.

dimensions

An integer vector of new dimensions.

Value

An array with new dimensions but the same size as x.

Examples

x <- 1:6

# Set the dimensions to turn a vector into a matrix
rray_set_dimensions(x, c(2L, 3L))

# Set the dimensions to turn a vector into a 3D array
rray_set_dimensions(x, c(3L, 2L, 1L))

# Setting dimensions can't change the size
try(rray_set_dimensions(x, c(6L, 2L)))

rray documentation built on Nov. 17, 2026, 5:07 p.m.