0

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

我心永恒
  • 1,488
  • 6
  • 9
  • 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.) – Michael E2 Mar 27 '23 at 13:49
  • @MichaelE2 As you can see, the list of the third layer connects the data, why not flatten the third layer?, I don't understand – 我心永恒 Mar 27 '23 at 13:51
  • In my view, the third layer was flattened. What do you mean - that is, what did you expect the output to be? – Michael E2 Mar 27 '23 at 13:52
  • @MichaelE2 How to understant levels of "Flatten" function? – 我心永恒 Mar 27 '23 at 13:53
  • 1
    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. – Michael E2 Mar 27 '23 at 13:58
  • Maybe mapping Transpose and then Flatten a level? – Daniel Lichtblau Mar 27 '23 at 14:07
  • @MichaelE2 The correct solution ”chatgpt“ as well solved, I am now confused – 我心永恒 Mar 27 '23 at 14:10
  • @xzczd I've seen this post before, but I don't understand it. I really don't understand the Flatten function – 我心永恒 Mar 27 '23 at 14:14
  • Also, since you can read Chinese, check this: https://tieba.baidu.com/p/2597584262 – xzczd Mar 27 '23 at 14:14
  • It's the best post about 2nd argument of Flatten in this site. If you still feel confused, please clarify which part you're having difficulty. – xzczd Mar 27 '23 at 14:16
  • @xzczd What's a more straightforward way to understand this function – 我心永恒 Mar 27 '23 at 14:17
  • @xzczd It is described in the help document as "layer", here it is more difficult to understand with corner notation – 我心永恒 Mar 27 '23 at 14:18
  • I don't think there exists a "more straightforward way". What you're expecting is just like, "I want to set an Assumptions option to integral, but I still want to use the pretty 2D . " <- This is just impossible, to set Assumptions you have to use the 1D Integrate[…] – xzczd Mar 27 '23 at 14:27
  • Also, notice that when explaining 2nd argument of Flatten, the document states: Flatten[list, {{$s_{11}$, $s_{12}$, …}, {$s_{21}$, $s_{22}$, …}, …}] flattens list by combining all levels $\color{red}{s_{ij}}$ to make each level $i$ in the result. It uses "corner notation", too. – xzczd Mar 27 '23 at 14:52

0 Answers0