I have a problem about the padding list
about Partition
command. For instance,
Partition[{a, b, c, d, e, f, g}, 3, 1, {-2, 1}, {x, y, z}]
{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, e}, {d, e, f}, {e, f, g}, {f,g, y}, {g, y, z}}
However, my understanding about padding list
shown as below:
Another example
Partition[{a, b, c, d, e, f}, 3, 3, {1, 1}]
{{a, b, c}, {d, e, f}}
My understanding:
Question
Can someone give me a good explanation?
Answer
Example #1
Let me make your example a bit smaller for brevity:
Partition[{a, b, c, d}, 3, 1, {-2, 1}, {x, y, z}]
{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, y}, {d, y, z}}
This is in effect:
PadRight[{a, b, c, d}, 7, {x, y, z}, 1]
Partition[%, 3, 1]
{z, a, b, c, d, y, z}
{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, y}, {d, y, z}}
Think instead:
+
Equals
Example #2
The documentation states:
Critical to your example is: "appear at or after position kR in the last sublist."
Therefore in this case it does not matter if kR is any of: 1
, 2
, 3
, -1
, -2
, -3
, because each will be satisfied by:
{{a, b, c}, {d, e, f}}
Partition
does not violate the cyclic order of the list. For the output to be as you anticipated:
{{a, b, c}, {d, e, f}, {f, a, b}}
The element f
would have to be taken out of sequence; the next element should be a
.
Comments
Post a Comment