Skip to contents

Combine arrays along the row (nv_rbind) or column (nv_cbind) dimension. Arguments are first promoted to a common data type (see nv_promote_to_common()).

Each input is then handled according to its rank:

  • 0-D: broadcast to match the non-stacked dimensions of the other inputs.

  • 1-D: treated as a single row/column.

  • Other: used as-is.

Usage

nv_rbind(...)

nv_cbind(...)

# S3 method for class 'AnvlArray'
rbind(..., deparse.level = 1)

# S3 method for class 'AnvlArray'
cbind(..., deparse.level = 1)

Arguments

...

(arrayish)
Arrays to combine. Inputs are promoted to a common data type.

deparse.level

Ignored. Kept for compatibility with base::rbind() and base::cbind().

Value

arrayish

Differences from base R

base::rbind() and base::cbind() applied to an array() of rank > 2 flatten the trailing dimensions into the column axis (so a c(2, 3, 4) array becomes a 2 x 12 matrix). nv_rbind and nv_cbind instead preserve all non-stacked dimensions: combining two c(2, 3, 4) arrays with nv_rbind produces a c(4, 3, 4) array, and with nv_cbind a c(2, 6, 4) array.

See also

Examples

# Vectors as rows / columns
nv_rbind(nv_array(1:3), nv_array(4:6))
#> AnvlArray
#>  1 2 3
#>  4 5 6
#> [ CPUi32{2,3} ] 
nv_cbind(nv_array(1:3), nv_array(4:6))
#> AnvlArray
#>  1 4
#>  2 5
#>  3 6
#> [ CPUi32{3,2} ] 

# Scalar broadcasting
nv_rbind(nv_matrix(1:6, nrow = 2), nv_scalar(0))
#> AnvlArray
#>  1 3 5
#>  2 4 6
#>  0 0 0
#> [ CPUf32{3,3} ] 

# Rank-3 arrays preserve trailing dimensions
a <- nv_array(1:24, shape = c(2, 3, 4))
shape(nv_rbind(a, a)) # c(4, 3, 4)
#> [1] 4 3 4