Consider the following table:


How is it possible to convert it into the form of a 2-column table tab1 where each subsequent 5 rows tab1[[i]],tab1[[i+1]],tab1[[i+2]],tab1[[i+3]],tab1[[i+4]] are

{tab[[i]][[1]], tab[[i]][[2]]}
{tab[[i]][[3]], tab[[i]][[4]]}
{tab[[i]][[5]], tab[[i]][[6]]}
{tab[[i]][[7]], tab[[i]][[8]]}
{tab[[i]][[9]], tab[[i]][[10]]}

It may be some way of using Riffle. Say,

tab1 = tab[[All, {1, 2}]];
Do[tabb = tab[[All, {i + 1, i + 2}]];
 tab1 = Riffle[tab1, tabb, i];
 , {i, 2, 5, 1}]

However, I am sure that there is a more elegant way.


1 Answer 1


We first create some data:

tab = RandomReal[{0, 1}, {5, 10}]

![![enter image description here

Then we destroy the structure using Flatten and reshape the array using ArrayReshape:

 ArrayReshape[Flatten[tab], {25, 2}] // MatrixForm

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.