Skip to contents

Roll array elements

Usage

mlx_roll(x, shift, axes = NULL)

Arguments

x

An mlx array.

shift

Integer vector giving the number of places by which elements are shifted.

axes

Optional integer vector (1-indexed) along which elements are shifted. When NULL, the array is flattened and shifted, then the shape is restored.

Value

An mlx array with elements circularly shifted. Dimnames are rolled with explicit axes; flattening rolls only keep names for vectors.

See also

Examples

x <- mlx_matrix(1:4, 2, 2)
mlx_roll(x, shift = 1, axes = 2)
#> mlx array [2 x 2]
#>   dtype: float32
#>   values:
#>      [,1] [,2]
#> [1,]    3    1
#> [2,]    4    2