rray_move_axes: Move array axes

View source: R/move-axes.R

rray_move_axesR Documentation

Move array axes

Description

rray_move_axes() takes axes from x and moves them to axes in the output. The axes that don't move keep their relative order, and fill in the locations that are left over.

Usage

rray_move_axes(x, ..., from, to)

Arguments

x

An array.

...

These dots are for future extensions and must be empty.

from

The axes to move, given by position.

to

The axes to move to, given by position in the output.

Details

Names and titles travel with their axis to its new position.

Value

An array.

See Also

rray_permute_axes()

Examples

x <- array(1:24, c(2, 3, 4))

# Move the first axis to the end
# (2, 3, 4) -> (3, 4, 2)
rray_dimensions(rray_move_axes(x, from = 1, to = 3))

# Move the last axis to the front
# (2, 3, 4) -> (4, 2, 3)
rray_dimensions(rray_move_axes(x, from = 3, to = 1))

# Move two axes at once, the axis that stays fills in what is left
# (2, 3, 4) -> (4, 2, 3)
rray_dimensions(rray_move_axes(x, from = c(1, 3), to = c(2, 1)))

# Swap the first two axes
# (2, 3, 4) -> (3, 2, 4)
rray_dimensions(rray_move_axes(x, from = c(1, 2), to = c(2, 1)))

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