Merging two 2-d arrays in order of axes
Consider using loops of length specific to the desired number of transactions.  For example, using this pseudo code create a sketch which follows this pattern:
initialize i to zero
loop 2 times for each row using the variable x
  loop 3 times for each element in first array using the variable y
    long array [i] = first array[x][y] 
    increment i
  loop 2 times for each element in a second array using the variable z
    long array [i] = second array[x][z]
    increment i