0

I am after a way to undo the array_reshape() function in R. Any help is welcomed.

library(reticulate) 

mat <- matrix(rep(1:1000), nrow = 10)

mat.1 <- array_reshape(mat, c(nrow(mat), 10,10,1)) 

# make mat.2 the same dimensions as mat
mat.2 <- ???
tora0515
  • 2,479
  • 12
  • 33
  • 40

2 Answers2

1

You can set the dim value of the array like this:

dim(mat.1) <- c(10, 100)
Allan Cameron
  • 147,086
  • 7
  • 49
  • 87
0

why not just do :

mat.2 = mat

if you avoid overwriting your first matrix, its still in memory just as before. when you operate on an object in R, R creates a copy automatically, so the operation you did on it was actually made on a copy.

dvd280
  • 876
  • 6
  • 11
  • haha, nice. But I will be doing some stuff to mat.1. Would like to make sure I put it back in the same order as it was. so whatever was in, say, mat[3,5] gets some stuff done to it while its in mat.1, then gets put back into mat.2[3,5];and so on – tora0515 May 21 '20 at 10:09