I have two matrices. They are,
m1={{a,b},{c,d}};
m2={{w,x},{y,z}};
I want to create a matrix of paired values that looks like this,
{{{a, w}, {b, x}}, {{c, y}, {d, z}}}
My equation for doing so looks like this,
Transpose /@ Transpose@{m1, m2}
and it works well; however, I thought I could use Map
to accomplish the same thing at two different levels of the input. I have been unsuccessful in doing so. I have tried things like,
Map[Transpose, {m1, m2}, {0, 1}]
which results in,
{{{a, c}, {w, y}}, {{b, d}, {x, z}}}
which is clearly not what I want.
Is there a way to use Map
in the above fashion and not call Transpose
twice as I have done in the successful example?
P.S. I have seen this example; however, the output format is incorrect for what I want. Yes, you could recreate the matrix dimensions with Partition
; however, I am looking for a more minimal expression.
Review of Answer Speeds
I reviewed the following answers for speed using Timing
.
Timing[Flatten[{m1,m2},{{2},{3}}]]][[1]]
(* 0.000021 *)
Timing[Transpose[{m1,m2},{3,1,2}]][[1]]
(* 0.000038 *)
Timing[MapThread[List,{m1,m2},2]][[1]]
(* 8.*10^-6 *)