Flatten array dimensions into a single dimension. This takes a multidimensional array and converts some dimensions of it into a vector. Use this to drop out "middle" dimensions of a structured array. This is conceptually the inverse of array_reshape
array_flatten(x, i)
An array
An integer vector of dimensions to flatten
A new array with at one or more dimensions removed
array_flatten which adds structure
x <- array(1:12, c(2, 3, 4))
mcstate::array_flatten(x, 2:3)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#> [1,] 1 3 5 7 9 11 1 3 5 7 9 11
#> [2,] 2 4 6 8 10 12 2 4 6 8 10 12
# array_flatten and array_reshape are each others' conceptual
# opposites:
y <- mcstate::array_flatten(x, 2:3)
identical(mcstate::array_reshape(y, 2, c(3, 4)), x)
#> [1] TRUE