Skip to contents

Inserts axes of size 1 at the specified positions.

Usage

nv_unsqueeze(x, axes)

Arguments

x

(arrayish)
One input. Can be any data type. An R value materializes at its default data type.

axes

(integer())
Positions of the new axes in the result, which has naxes(x) + length(axes) axes. Negative values count from the end of the result, i.e. -1 appends a new axis at the end.

Value

(arrayish)
Has x's data type, with an extra axis of size 1 in its shape for each of axes.

Examples

# a size-1 axis is inserted, at the front or at the back
x <- nv_array(c(1, 2, 3))
nv_unsqueeze(x, axes = 1L)
#> AnvlArray
#>  1 2 3
#> [ CPUf32{1,3} ] 
nv_unsqueeze(x, axes = -1L)
#> AnvlArray
#>  1
#>  2
#>  3
#> [ CPUf32{3,1} ] 

# several at once
nv_unsqueeze(x, axes = c(1L, 3L))
#> AnvlArray
#> (1,.,.) =
#>  1
#>  2
#>  3
#> [ CPUf32{1,3,1} ]