Skip to contents

Concatenates arrays along an axis. Operands are promoted to a common data type and scalars are broadcast before concatenation.

You can also use c() on scalars and 1-D arrays, like base R.

Usage

nv_concatenate(..., axis = NULL)

Arguments

...

(arrayish)
Arrays to concatenate. Can be of any data type; they are promoted to a common data type and scalars are broadcast. Must have the same shape except along axis.

axis

(integer(1) | NULL)
Axis along which to concatenate. Negative values count from the end, i.e. -1 refers to the last axis. If NULL (default), concatenates along axis 1, which requires every input to have at most one axis; for anything else axis must be given, since there is no neutral axis to join two matrices along.

Value

(arrayish)
Has the common data type and a shape matching the inputs in all axes except axis, which is the sum of input sizes.

The c() generic

c() concatenates scalars and 1-D arrays into a 1-D array, like base::c() does for vectors. An array with more than one axis is an error rather than being flattened the way base R does; concatenate those along an explicit axis, or nv_flatten() them first.

See also

prim_concatenate() for the underlying primitive.

Examples

# the operands are promoted to a common data type; axis 1 grows to 6
x <- nv_array(c(1, 2, 3))
y <- nv_array(c(4, 5, 6))
nv_concatenate(x, y)
#> AnvlArray
#>  1
#>  2
#>  3
#>  4
#>  5
#>  6
#> [ CPUf32{6} ] 

m <- nv_matrix(1:4, nrow = 2)
nv_concatenate(m, m, axis = 1L) # required: `m` has two axes
#> AnvlArray
#>  1 3
#>  2 4
#>  1 3
#>  2 4
#> [ CPUi32{4,2} ]