Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I know it may sounds idiot, but I've been looking through the document, and couldn't find a way to combine two vectors say {a, b} and {c, d} into {{a, c}, {b, d}}.

Thanks all.

share|improve this question
4  
Transpose[{{a,b},{c,d}}] –  Timothy Wofford Dec 10 '13 at 7:55
1  
OP wanted {{a,c},{b,d}} which is a concatenation by columns. –  FrenzY DT. Dec 10 '13 at 7:57
add comment

2 Answers

up vote 7 down vote accepted

You are treating $A$ and $B$ as column vectors and combining them column to column, but if you just bracket the two vectors, you are combining them row to row. A final Transpose will do the trick.

A = {a, b};
B = {c, d};
NotYourResult = {A,B}
Result = Transpose[{A, B}]

where NotYourResult is assigned {{a,b},{c,d}} or $\left[ {\begin{array}{cc} a & b \\ c & d \\ \end{array} } \right]$,

and Result is assigned {{a,c},{b,d}} or $\left[ {\begin{array}{cc} a & c \\ b & d \\ \end{array} } \right]$,

share|improve this answer
    
Thanks for reminding ^_^ –  load of sweet Dec 10 '13 at 13:27
add comment

Thread can be useful, too:

A = {a, b};
B = {c, d};

Thread[{A, B}]

{{a, c}, {b, d}}

The canonical Q&A for this kind of stuff probably is Elegant operations on matrix rows and columns.

share|improve this answer
    
Thanks for supplement –  load of sweet Dec 10 '13 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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