0
$\begingroup$

This question already has an answer here:

Recently, I have been reading Mathematica program that written by many advanced Mathematica user, like Mr.Wizard, J.M., Kuba,etc to improve my programming capacity

In the On generalizing Partition[] (with offsets) to sublists of unequal length

I read the program of Mr.Wizard about dpCyclicwhich owns a line code shown as below:

MapThread[blocks[[All, # ;; #2]] &, ranges] ~Flatten~ {2, 1}

I cannot under the useage of Flatten[list,{2,1}]

So I look up the Wolfram Help Documentation

enter image description here

And it has a example:

u = {{a, b}, {c, d}};
Flatten[{{u, 0 u}, {0 u, u}}, {{1, 3}, {2, 4}}] // MatrixForm

enter image description here

Or

Flatten[{{1}, {2, 3}, {3, 4, 5}, {4, 5, 6, 7}}, {{2}, {1}}]

{{1, 2, 3, 4}, {3, 4, 5}, {5, 6}, {7}}

However,I cannot understand their result correctly.

So my question is :

1.How to understand extensional usage of Flatten?

2.In Flatten[{{1}, {2, 3}, {3, 4, 5}, {4, 5, 6, 7}}, {{2}, {1}}],how to use the argument {{2}, {1}} correctly, Namely, why I cannot use {{2}, {2}}?

$\endgroup$

marked as duplicate by Leonid Shifrin, eldo, C. E., bobthechemist, m_goldberg Sep 15 '14 at 16:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

As far as I understand it is used as follows: The mentioned example:

Flatten[list, {{2}, {1}}]

takes of all elements in list first the first elements (s_{1,j} building the first new list). This leads to: {1, 2, 3, 4}, then (from the remaining) lists the next elements -> {3, 4, 5}, then the third: {5, 6}, an lastly, the fourth, the list {7}.

Greetings from Germany

Mike

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.