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 have a set of n vectors with an even length. Let us make an easy example with 3 vectors of length=4:

 a={a1,a2,a3,a4}
 b={b1,b2,b3,b4}
 c={c1,c2,c3,c4}

I want to create the vectors:

 d1={a1,a2}
 d2={a3,a4}

 e1={b1,b2}
 e2={b3,b4}

 f1={c1,c2}
 f2={c3,c4}

I suppose I have to use GatherBy, but I have not found the way to get what I want.

share|improve this question
2  
Have a look at Partition. –  b.gatessucks Feb 26 '13 at 15:58
2  
This is the latest of many questions you have asked that are all incorrectly tagged [sparse-arrays]. Please ensure that you use tags that are relevant to the topic of your question. –  Oleksandr R. Feb 26 '13 at 16:20
add comment

1 Answer

up vote 2 down vote accepted
a = {a1, a2, a3, a4}; b = {b1, b2, b3, b4}; c = {c1, c2, c3, c4}; 
{d1, d2, e1, e2, f1, f2} = Partition[Join[a, b, c], 2]

Also

{{d1, d2}, {e1, e2}, {f1, f2}} = Partition[#, 2] & /@ {a, b, c}
share|improve this answer
    
You beat me by seconds! +1, I respectfully withdrawal –  Jagra Feb 26 '13 at 16:19
    
Actually wouldn't this prove more general for even lengthed lists: {{d1, d2}, {e1, e2}, {f1, f2}} = Partition[#, Length[#]/2] & /@ {a, b, c}; –  Jagra Feb 26 '13 at 16:21
1  
@Jagra The question could be "generalized" in every direction you may think of :) . I really dislike naming sublists like that, no need. –  belisarius Feb 26 '13 at 16:42
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.