Reshape (reindex) a multi-dimensional array, using row-major (C-style) reshaping semantics by default.
array_reshape(x, dim, order = c("C", "F"))
The new dimensions to be set on the array.
The order in which elements of
This function differs from e.g.
dim(x) <- dim in a very important way: by
array_reshape() will fill the new dimensions in row-major (
dim<-() will fill new dimensions in column-major
Fortran-style) ordering. This is done to be consistent with libraries
like NumPy, Keras, and TensorFlow, which default to this sort of ordering when
reshaping arrays. See the examples for why this difference may be important.
## Not run: # let's construct a 2x2 array from a vector of 4 elements x <- 1:4 # rearrange will fill the array row-wise array_reshape(x, c(2, 2)) # [,1] [,2] # [1,] 1 2 # [2,] 3 4 # setting the dimensions 'fills' the array col-wise dim(x) <- c(2, 2) x # [,1] [,2] # [1,] 1 3 # [2,] 2 4 ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.