Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

If I understand your question I previously wrote a functionpreviously wrote a function for this purpose.
The core of that function is:

If I understand your question I previously wrote a function for this purpose.
The core of that function is:

If I understand your question I previously wrote a function for this purpose.
The core of that function is:

replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Please note that one special but practically important case is when the list you want to split is a packed arraypacked array, or can be converted into one. Here is an illustration. First, we create a large (and apparently unpacked) test list:

The technique of converting sub-lists of a ragged lists to packed form was already discussed a few times here on SE, e.g. herehere. In this particular case, dynP will do that automatically when the initial list is packed, but it is still good to keep in mind, for example to avoid accidental unpacking of sublists during whatever further processing you want to perform on the resulting ragged list.

Please note that one special but practically important case is when the list you want to split is a packed array, or can be converted into one. Here is an illustration. First, we create a large (and apparently unpacked) test list:

The technique of converting sub-lists of a ragged lists to packed form was already discussed a few times here on SE, e.g. here. In this particular case, dynP will do that automatically when the initial list is packed, but it is still good to keep in mind, for example to avoid accidental unpacking of sublists during whatever further processing you want to perform on the resulting ragged list.

Please note that one special but practically important case is when the list you want to split is a packed array, or can be converted into one. Here is an illustration. First, we create a large (and apparently unpacked) test list:

The technique of converting sub-lists of a ragged lists to packed form was already discussed a few times here on SE, e.g. here. In this particular case, dynP will do that automatically when the initial list is packed, but it is still good to keep in mind, for example to avoid accidental unpacking of sublists during whatever further processing you want to perform on the resulting ragged list.

added 1 characters in body
Source Link
Heike
  • 36.2k
  • 3
  • 111
  • 158
dPcore[L_, p : {q__q___, _}] := Inner[L[[# ;; #2]] &, {0, q} + 1, p, Head@L] dPcore[L_, p_, All] := dPcore[L, p] ~Append~ Drop[L, Last@p] dPcore[L_, p_, n__] := dPcore[L, p] ~Join~ Partition[L ~Drop~ Last@p, n] dynamicPartition[L_, p : {__Integer}, x___] := dPcore[L, Accumulate@p, x] /; ! Negative@Min@p && Length@L >= Tr@p 
dPcore[L_, p : {q__, _}] := Inner[L[[# ;; #2]] &, {0, q} + 1, p, Head@L] dPcore[L_, p_, All] := dPcore[L, p] ~Append~ Drop[L, Last@p] dPcore[L_, p_, n__] := dPcore[L, p] ~Join~ Partition[L ~Drop~ Last@p, n] dynamicPartition[L_, p : {__Integer}, x___] := dPcore[L, Accumulate@p, x] /; ! Negative@Min@p && Length@L >= Tr@p 
dPcore[L_, p : {q___, _}] := Inner[L[[# ;; #2]] &, {0, q} + 1, p, Head@L] dPcore[L_, p_, All] := dPcore[L, p] ~Append~ Drop[L, Last@p] dPcore[L_, p_, n__] := dPcore[L, p] ~Join~ Partition[L ~Drop~ Last@p, n] dynamicPartition[L_, p : {__Integer}, x___] := dPcore[L, Accumulate@p, x] /; ! Negative@Min@p && Length@L >= Tr@p 
added 417 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading
Added a section on packed arrays, restructured; added 135 characters in body; added 4 characters in body
Source Link
Leonid Shifrin
  • 115.8k
  • 16
  • 341
  • 435
Loading
added 1000 characters in body; deleted 67 characters in body; added 1 characters in body; added 6 characters in body; deleted 1 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading
added 101 characters in body; added 6 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading