Skip to main content
added 10 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

In the spirit of Mathematica 10 I would have written it like this:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

The first method assumes numeric matrix elements but the second doesn't.

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

The first method assumes numeric matrix elements but the second doesn't.

In the spirit of Mathematica 10 I would have written it like this:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

The first method assumes numeric matrix elements but the second doesn't.

added 133 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

The first method assumes numeric matrix elements but the second doesn't.

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

The first method assumes numeric matrix elements but the second doesn't.

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

The first method assumes numeric matrix elements but the second doesn't.

added 135 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

The first method assumes numeric matrix elements but the second doesn't.

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

In the spirit of Mathematica 10 I would have written it:

Composition[
  DeleteCases[{{0} ..}],
  Map[Transpose],
  SplitBy[#, Unitize@*Total] &,
  Transpose
  ]@mat

{{{0, 0}, {1, 0}, {0, 1}, {0, 0}, {1, 1}, {0, 0}}, {{0}, {1}, {0}, {0}, {1}, {1}}, {{1}, {1}, {0}, {1}, {0}, {1}}}

With rules I would write:

Transpose /@ {Transpose[mat] //. {el__, {0 ..}, rest___} :> Sequence[{el}, {rest}]}

The first method assumes numeric matrix elements but the second doesn't.

Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading