Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. Flatten[list, {{s11, s12, ...}, {s21, s22, ...}, ...}]
  2.  
  3. In[63]:= Flatten[{{1,2,3},{4,5},{6,7},{8,9,10}},{{2},{1}}]
  4. Out[63]= {{1,4,6,8},{2,5,7,9},{3,10}}
  5.  
  6. In[65]:= Flatten[{{1,4,6,8},{2,5,7,9},{3,10}},{{2},{1}}]
  7. Out[65]= {{1,2,3},{4,5,10},{6,7},{8,9}}
  8.  
  9. In[67]:= Flatten/@Flatten[{{1,4,6,8},{2,5,7,9},{3,{},{},10}},{{2},{1}}]
  10. Out[67]= {{1,2,3},{4,5},{6,7},{8,9,10}}
  11.  
  12. In[68]:= Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{2},{1},{3}}]
  13. Out[68]= {{{1,2,3},{6,7}},{{4,5},{8,9,10}}}
  14.  
  15. In[69]:= Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{3}, {1}, {2}}]
  16. Out[69]= {{{1, 4}, {6, 8}}, {{2, 5}, {7, 9}}, {{3}, {10}}}
  17.  
  18. In[72]:= step1 = Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{1},{3},{2}}]
  19. Out[72]= {{{1,4},{2,5},{3}},{{6,8},{7,9},{10}}}
  20.  
  21. In[73]:= step2 = Flatten[step1,{{2},{1},{3}}]
  22. Out[73]= {{{1,4},{6,8}},{{2,5},{7,9}},{{3},{10}}}
  23.  
  24. Flatten[{{{111, 112, 113}, {121, 122}}, {{211, 212}, {221, 222, 223}}}, {{3}, {1}, {2}}]
  25. (*
  26. ==> {{{111, 121}, {211, 221}}, {{112, 122}, {212, 222}}, {{113}, {223}}}
  27. *)
  28.  
  29. In[74]:= Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{2},{1,3}}]
  30. Out[74]= {{1,2,3,6,7},{4,5,8,9,10}}
  31.  
  32. $m = Array[Subscript[m, Row[{##}]]&, {4, 3, 2}];
  33. $m // MatrixForm
  34.  
  35. $m === Table[$m[[i, j, k]], {i, 1, 4}, {j, 1, 3}, {k, 1, 2}]
  36. (* True *)
  37.  
  38. $r = Table[$m[[i, j, k]], {j, 1, 3}, {i, 1, 4}, {k, 1, 2}];
  39. $r // MatrixForm
  40.  
  41. $r === Flatten[$m, {{2}, {1}, {3}}]
  42. (* True *)
  43.  
  44. $m === Flatten[$m, {{1}, {2}, {3}}]
  45. (* True *)
  46.  
  47. Flatten[$m, {{3}, {2}, {1}}] // MatrixForm
  48.  
  49. Flatten[$m, {{3}}] === Flatten[$m, {{3}, {1}, {2}}]
  50. (* True *)
  51.  
  52. Flatten[$m, {3}] === Flatten[$m, {{3}}]
  53. (* True *)
  54.  
  55. $m === Flatten[$m, {}] === Flatten[$m, {1}] === Flatten[$m, {{1}, {2}, {3}}]
  56. (* True *)
  57.  
  58. Flatten[$m, {{1}, {2}, {3}}] // MatrixForm
  59.  
  60. Flatten[$m, {{1, 2}, {3}}] // MatrixForm
  61.  
  62. Flatten[$m, {{1}, {2, 3}}] // MatrixForm
  63.  
  64. Flatten[$m, {{1, 2, 3}}]
  65.  
  66. Flatten[$m, {{1, 2, 3}}] === Flatten[$m, {1, 2, 3}] === Flatten[$m]
  67. (* True *)
  68.  
  69. $n = Array[n[##]&, {2, 2, 2, 2, 2}];
  70.  
  71. Flatten[$n, {{1}, {2}, {3}, {4}, {5}}] === Flatten[$n, 0]
  72. (* True *)
  73.  
  74. Flatten[$n, {{1, 2}, {3}, {4}, {5}}] === Flatten[$n, 1]
  75. (* True *)
  76.  
  77. Flatten[$n, {{1, 2, 3}, {4}, {5}}] === Flatten[$n, 2]
  78. (* True *)
  79.  
  80. Flatten[$n, {{1, 2, 3, 4}, {5}}] === Flatten[$n, 3]
  81. (* True *)
  82.  
  83. $t = Array[# Range[#]&, {5}];
  84. $t // TableForm
  85. (*
  86. 1
  87. 2 4
  88. 3 6 9
  89. 4 8 12 16
  90. 5 10 15 20 25
  91. *)
  92.  
  93. Flatten[$t, {{2}, {1}}] // TableForm
  94. (*
  95. 1 2 3 4 5
  96. 4 6 8 10
  97. 9 12 15
  98. 16 20
  99. 25
  100. *)
  101.  
  102. Flatten[$t, {{2, 1}}]
  103. (* {1,2,3,4,5,4,6,8,10,9,12,15,16,20,25} *)
  104.  
  105. lists = {
  106. {{{1, 0}, {1, 1}}, {{2, 0}, {2, 4}}, {{3, 0}}},
  107. {{{1, 2}, {1, 3}}, {{2, Sqrt[2]}}, {{3, 4}}}
  108. (*, more lists... *)
  109. };
  110.  
  111. list2 = {
  112. {{1, 0}, {1, 1}, {2, 0}, {2, 4}, {3, 0}},
  113. {{1, 2}, {1, 3}, {2, Sqrt[2]}, {3, 4}}
  114. (*, more lists... *)
  115. }
  116.  
  117. list2 = Flatten[lists, {{1}, {2, 3}}];
  118.  
  119. TreeForm@{{1,2},{3,4}}
  120.  
  121. {<|"index" -> {1, 1}, "value" -> 1|>, <|"index" -> {1, 2}, "value" -> 2|>, <|"index" -> {2, 1}, "value" -> 3|>, <|"index" -> {2, 2}, "value" -> 4|>}
  122.  
  123. Flatten[mat,{{2},{1}}]
  124.  
  125. Flatten[mat,{{1,2}}]
  126.  
  127. {{{{1,2},{5,6}},{{3,4},{7,8}}},{{{9,10},{13,14}},{{11,12},{15,16}}}}
  128.  
  129. Flatten[mat,{{1,3},{2,4}}]
  130.  
  131. img=Image@RandomReal[1,{10,10}]
  132.  
  133. ConstantArray[ImageData@img,{10,10}]
  134.  
  135. Image@Flatten[ConstantArray[ImageData@img,{10,10}],{{3,1},{4,2}}]
Add Comment
Please, Sign In to add comment