title: Change dimensions of array in R
body: <p>I have a 3D array:</p>
  
  <pre><code>my.array &lt;- array(1:120, dim=c(3,4,10))
  
  dim(my.array)
  [1]  3  4 10
  </code></pre>
  
  <p>3,4 are width,height of matrix and 10 number of matrices. To be in accordance with Keras input (number of matrices first), I want to change the order of dimensions as:</p>
  
  <pre><code>dim(my.array)
  [1]  10  3  4
  </code></pre>
  
  <p>The first matrix is:</p>
  
  <pre><code>my.array[,,1]
       [,1] [,2] [,3] [,4]
  [1,]    1    4    7   10
  [2,]    2    5    8   11
  [3,]    3    6    9   12
  </code></pre>
  
  <p>If I do <code>dim(my.array) &lt;- c(10, 3, 4)</code>. My first matrix will:</p>
  
  <pre><code>my.array[1,,]
       [,1] [,2] [,3] [,4]
  [1,]    1   31   61   91
  [2,]   11   41   71  101
  [3,]   21   51   81  111
  </code></pre>
  
  <p>So it is not correct because it changes the order of values. The first matrix after the modification must be:</p>
  
  <pre><code>my.array[1,,]
           [,1] [,2] [,3] [,4]
      [1,]    1    4    7   10
      [2,]    2    5    8   11
      [3,]    3    6    9   12
  </code></pre>