Group Abstract Group Abstract

Message Boards Message Boards

0
|
44 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Flattening multilevel list formats

Posted 20 hours ago
{{{{36 - 72 m^2}, {-36}, {9 + 8 m^2}}, {{4 - 2 e m - 9 m^2 + 
         3 d m^2}, {-4 + e m + d m^2}, {1 + m^2}}}, {{{-40, 32 m, 
        9 + 8 m^2}}, {{-5 + 5 d, e + 4 m + d m, 1 + m^2}}}}

How to convert the above output into the format shown below?

{{{36 - 72 m^2, -36, 
   9 + 8 m^2}, {4 - 2 e m - 9 m^2 + 3 d m^2, -4 + e m + d m^2, 
   1 + m^2}}, {{-40, 32 m, 9 + 8 m^2}, {-5 + 5 d, e + 4 m + d m, 
   1 + m^2}}}

My current implementation seems suboptimal in terms of conciseness. Could you suggest more efficient methods?

original = {{{{36 - 72 m^2}, {-36}, {9 + 8 m^2}}, {{4 - 2 e m - 
       9 m^2 + 3 d m^2}, {-4 + e m + d m^2}, {1 + m^2}}}, {{{-40, 
      32 m, 9 + 8 m^2}}, {{-5 + 5 d, e + 4 m + d m, 1 + m^2}}}};
firstLayer = Flatten /@ original[[1]];
secondLayer = Flatten /@ original[[2]];
result = {firstLayer, secondLayer}
POSTED BY: Jim Clinton
5 Replies

This flattens levels 3 and 4:

Flatten[original, {{1}, {2}, {3, 4}}]
POSTED BY: Gianluca Gorni
Posted 6 hours ago
original = {{{{36 - 72 m^2}, {-36}, {9 + 8 m^2}}, {{4 - 2 e m - 
       9 m^2 + 3 d m^2}, {-4 + e m + d m^2}, {1 + m^2}}}, {{{-40, 
      32 m, 9 + 8 m^2}}, {{-5 + 5 d, e + 4 m + d m, 1 + m^2}}}};
Map[Flatten, original, {2}]
POSTED BY: Jim Clinton
Posted 6 hours ago

Great method, it utilizes level operations—thank you very much!

POSTED BY: Jim Clinton
Posted 6 hours ago

This method is great, thank you very much!

POSTED BY: Jim Clinton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard