0
$\begingroup$

I have a data

data={{{-(1/2), -(3/2)}, {1/2, -(1/2)}, {3/2, 1/
   2}}, {{-(3/2), -(5/2)}, {-(1/2), -(3/2)}, {1/2, -(1/2)}, {3/2, 1/
   2}, {5/2, 3/2}}}

I want to change this data to this enter image description here

Inorder solve this ploblem I can use

TreeForm@data

get this

enter image description here

By looking at the data, I found that the second part lsit should be deleted enter image description here

I want to get rid of all the parentheses here

enter image description here

I tried a lot of things to no avail, so I finally asked "chatgpt"

Flatten[data, {{1}, {2, 3}}]

enter image description here

The problem is solved, but I don't understand how to use the "layer number" in Flatten, I'm confused

$\endgroup$
14
  • $\begingroup$ Flatten left layer (aka level) 1 alone and flattened layers 2 and 3. (You have layer 3 outlined in the red box. Everything below it was put into layer two, divided according to layer 2.) $\endgroup$
    – Michael E2
    Commented Mar 27, 2023 at 13:49
  • $\begingroup$ @MichaelE2 As you can see, the list of the third layer connects the data, why not flatten the third layer?, I don't understand $\endgroup$ Commented Mar 27, 2023 at 13:51
  • $\begingroup$ In my view, the third layer was flattened. What do you mean - that is, what did you expect the output to be? $\endgroup$
    – Michael E2
    Commented Mar 27, 2023 at 13:52
  • $\begingroup$ @MichaelE2 How to understant levels of "Flatten" function? $\endgroup$ Commented Mar 27, 2023 at 13:53
  • 1
    $\begingroup$ The flatten code says leave level 1 alone and flatten each item in level with its contents down to level 3. The hard one to describe is when the levels are transposed, such as in Flatten[data, {{1, 3}, {2}}], which might be the code you desire. $\endgroup$
    – Michael E2
    Commented Mar 27, 2023 at 13:58

0

Browse other questions tagged or ask your own question.