1
$\begingroup$

When trying to concatenate matrices i usually use Join. But having the matrices in an array it gets tricky.

As an example:

 A = IdentityMatrix[2];
 B = 2*IdentityMatrix[2];
 mArray = {A,B};

I'd like to have something to obtain the same result of Join[A,B,2] (concatenating A with B on the right), while having the matrices on an array.

I tried something like Apply[Join[#,2]&,mArray] without luck.

$\endgroup$
3
  • 3
    $\begingroup$ Join[##,2]&@@mArray or Join[Sequence @@ mArray, 2] $\endgroup$ Commented Mar 31, 2023 at 16:45
  • 6
    $\begingroup$ ArrayFlatten[{mArray}] $\endgroup$
    – Syed
    Commented Mar 31, 2023 at 16:59
  • 1
    $\begingroup$ @HenrikSchumacher Thanks, i did not know about the slotsequence ##. $\endgroup$
    – zurg
    Commented Mar 31, 2023 at 17:27

2 Answers 2

3
$\begingroup$

Using Catenate:

Transpose@Catenate[mArray]

(*{{1, 0, 2, 0}, {0, 1, 0, 2}}*)
$\endgroup$
3
$\begingroup$
a = IdentityMatrix[2];

b = 2 * IdentityMatrix[2];

MapThread[Join, {a, b}]

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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