Skip to main content
Simplify code based on roman's suggestion
Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

Suppose you have 4 matrices:

SeedRandom[1]
{a, b, c, d} = RandomInteger[1, {4, 2, 2}];

Then, you can use a combination of ArrayReshape and Transpose to construct the desired matrix:

ArrayReshape[Transpose[Transpose[{a, b, c, d}, {3, 1, 2}], {2, 2, 4}]

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

Suppose you have 4 matrices:

SeedRandom[1]
{a, b, c, d} = RandomInteger[1, {4, 2, 2}];

Then, you can use a combination of ArrayReshape and Transpose to construct the desired matrix:

ArrayReshape[Transpose[{a, b, c, d}, {3, 1, 2}], {2, 2, 4}]

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

Suppose you have 4 matrices:

SeedRandom[1]
{a, b, c, d} = RandomInteger[1, {4, 2, 2}];

Then, you can use Transpose to construct the desired matrix:

Transpose[{a, b, c, d}, {3, 1, 2}]

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

Source Link
Carl Woll
  • 131.7k
  • 6
  • 246
  • 359

Suppose you have 4 matrices:

SeedRandom[1]
{a, b, c, d} = RandomInteger[1, {4, 2, 2}];

Then, you can use a combination of ArrayReshape and Transpose to construct the desired matrix:

ArrayReshape[Transpose[{a, b, c, d}, {3, 1, 2}], {2, 2, 4}]

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