4
$\begingroup$

I need to restructure this list nums:

nums = {{0.0140242, 0.138626, 0.0585034, 0.0509646, 0.0629815, 0.0750587, 
  0.00588226, 0.272169, 1.},
 {0.153123, 0.212751, 0.217497, 0.12154, 0.210508, 0.189625, 0.0680384, 
  0.0768402, 0.172107},
 {0.20766, 0.246923, 0.0924592, 0.142682, 0.110408, 0.20464, 0.246233, 
  0.251928, 0.07382}};

based on the following rules:

  • Every 2nd element in each sublist should be moved/appended to a new vector immediately following its original vector
  • Every 3rd element in each sublist should be moved/appended to a new vector immediately following its original vector and the 2nd elements vector

The resulting list should look like:

{{0.0140242, 0.0509646, 0.00588226},
 {0.138626, 0.0629815, 0.272169},         // new 2nd elements vector
 {0.0585034, 0.0750587, 1.},              // new 3rd elements vector
 {0.153123, 0.12154, 0.0680384},
 {0.212751, 0.210508, 0.0768402},         // new 2nd elements vector
 {0.217497, 0.189625, 0.172107},          // new 3rd elements vector
 {0.20766, 0.142682, 0.246233},
 {0.246923, 0.110408, 0.251928},          // new 2nd elements vector
 {0.0924592, 0.20464, 0.07382}}           // new 3rd elements vector
$\endgroup$
5
$\begingroup$
Join @@ Transpose[nums[[All, # ;; ;; 3]] & /@ {1, 2, 3}]

{{0.0140242, 0.0509646, 0.00588226},
{0.138626, 0.0629815, 0.272169},
{0.0585034, 0.0750587, 1.},
{0.153123, 0.12154, 0.0680384},
{0.212751, 0.210508, 0.0768402},
{0.217497, 0.189625, 0.172107},
{0.20766, 0.142682, 0.246233},
{0.246923, 0.110408, 0.251928},
{0.0924592, 0.20464, 0.07382}}

Also

Flatten[Partition[nums, {3, 3}], {3, 4, 1}]

same result

$\endgroup$
6
$\begingroup$
Flatten[Transpose@Partition[#,3]&/@nums,1]     

{{0.0140242,0.0509646,0.00588226},
{0.138626,0.0629815,0.272169},
{0.0585034,0.0750587,1.},
{0.153123,0.12154,0.0680384},
{0.212751,0.210508,0.0768402},
{0.217497,0.189625,0.172107},
{0.20766,0.142682,0.246233},
{0.246923,0.110408,0.251928},
{0.0924592,0.20464,0.07382}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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