Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Flatten[list, {{s11, s12, ...}, {s21, s22, ...}, ...}]
- In[63]:= Flatten[{{1,2,3},{4,5},{6,7},{8,9,10}},{{2},{1}}]
- Out[63]= {{1,4,6,8},{2,5,7,9},{3,10}}
- In[65]:= Flatten[{{1,4,6,8},{2,5,7,9},{3,10}},{{2},{1}}]
- Out[65]= {{1,2,3},{4,5,10},{6,7},{8,9}}
- In[67]:= Flatten/@Flatten[{{1,4,6,8},{2,5,7,9},{3,{},{},10}},{{2},{1}}]
- Out[67]= {{1,2,3},{4,5},{6,7},{8,9,10}}
- In[68]:= Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{2},{1},{3}}]
- Out[68]= {{{1,2,3},{6,7}},{{4,5},{8,9,10}}}
- In[69]:= Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{3}, {1}, {2}}]
- Out[69]= {{{1, 4}, {6, 8}}, {{2, 5}, {7, 9}}, {{3}, {10}}}
- In[72]:= step1 = Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{1},{3},{2}}]
- Out[72]= {{{1,4},{2,5},{3}},{{6,8},{7,9},{10}}}
- In[73]:= step2 = Flatten[step1,{{2},{1},{3}}]
- Out[73]= {{{1,4},{6,8}},{{2,5},{7,9}},{{3},{10}}}
- Flatten[{{{111, 112, 113}, {121, 122}}, {{211, 212}, {221, 222, 223}}}, {{3}, {1}, {2}}]
- (*
- ==> {{{111, 121}, {211, 221}}, {{112, 122}, {212, 222}}, {{113}, {223}}}
- *)
- In[74]:= Flatten[{{{1,2,3},{4,5}},{{6,7},{8,9,10}}},{{2},{1,3}}]
- Out[74]= {{1,2,3,6,7},{4,5,8,9,10}}
- $m = Array[Subscript[m, Row[{##}]]&, {4, 3, 2}];
- $m // MatrixForm
- $m === Table[$m[[i, j, k]], {i, 1, 4}, {j, 1, 3}, {k, 1, 2}]
- (* True *)
- $r = Table[$m[[i, j, k]], {j, 1, 3}, {i, 1, 4}, {k, 1, 2}];
- $r // MatrixForm
- $r === Flatten[$m, {{2}, {1}, {3}}]
- (* True *)
- $m === Flatten[$m, {{1}, {2}, {3}}]
- (* True *)
- Flatten[$m, {{3}, {2}, {1}}] // MatrixForm
- Flatten[$m, {{3}}] === Flatten[$m, {{3}, {1}, {2}}]
- (* True *)
- Flatten[$m, {3}] === Flatten[$m, {{3}}]
- (* True *)
- $m === Flatten[$m, {}] === Flatten[$m, {1}] === Flatten[$m, {{1}, {2}, {3}}]
- (* True *)
- Flatten[$m, {{1}, {2}, {3}}] // MatrixForm
- Flatten[$m, {{1, 2}, {3}}] // MatrixForm
- Flatten[$m, {{1}, {2, 3}}] // MatrixForm
- Flatten[$m, {{1, 2, 3}}]
- Flatten[$m, {{1, 2, 3}}] === Flatten[$m, {1, 2, 3}] === Flatten[$m]
- (* True *)
- $n = Array[n[##]&, {2, 2, 2, 2, 2}];
- Flatten[$n, {{1}, {2}, {3}, {4}, {5}}] === Flatten[$n, 0]
- (* True *)
- Flatten[$n, {{1, 2}, {3}, {4}, {5}}] === Flatten[$n, 1]
- (* True *)
- Flatten[$n, {{1, 2, 3}, {4}, {5}}] === Flatten[$n, 2]
- (* True *)
- Flatten[$n, {{1, 2, 3, 4}, {5}}] === Flatten[$n, 3]
- (* True *)
- $t = Array[# Range[#]&, {5}];
- $t // TableForm
- (*
- 1
- 2 4
- 3 6 9
- 4 8 12 16
- 5 10 15 20 25
- *)
- Flatten[$t, {{2}, {1}}] // TableForm
- (*
- 1 2 3 4 5
- 4 6 8 10
- 9 12 15
- 16 20
- 25
- *)
- Flatten[$t, {{2, 1}}]
- (* {1,2,3,4,5,4,6,8,10,9,12,15,16,20,25} *)
- lists = {
- {{{1, 0}, {1, 1}}, {{2, 0}, {2, 4}}, {{3, 0}}},
- {{{1, 2}, {1, 3}}, {{2, Sqrt[2]}}, {{3, 4}}}
- (*, more lists... *)
- };
- list2 = {
- {{1, 0}, {1, 1}, {2, 0}, {2, 4}, {3, 0}},
- {{1, 2}, {1, 3}, {2, Sqrt[2]}, {3, 4}}
- (*, more lists... *)
- }
- list2 = Flatten[lists, {{1}, {2, 3}}];
- TreeForm@{{1,2},{3,4}}
- {<|"index" -> {1, 1}, "value" -> 1|>, <|"index" -> {1, 2}, "value" -> 2|>, <|"index" -> {2, 1}, "value" -> 3|>, <|"index" -> {2, 2}, "value" -> 4|>}
- Flatten[mat,{{2},{1}}]
- Flatten[mat,{{1,2}}]
- {{{{1,2},{5,6}},{{3,4},{7,8}}},{{{9,10},{13,14}},{{11,12},{15,16}}}}
- Flatten[mat,{{1,3},{2,4}}]
- img=Image@RandomReal[1,{10,10}]
- ConstantArray[ImageData@img,{10,10}]
- Image@Flatten[ConstantArray[ImageData@img,{10,10}],{{3,1},{4,2}}]
Add Comment
Please, Sign In to add comment