Skip to contents

Inserts an axis of size 1 at the specified position.

Usage

nv_unsqueeze(x, axis)

Arguments

x

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

axis

(integer(1))
Position at which to insert the new axis. Valid positions range from 1 to naxes(x) + 1. Negative values count from the end of the result, i.e. -1 appends the new axis at the end.

Value

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

Examples

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