5
$\begingroup$

This question already has an answer here:

I use mathematica 9.0

I tried it often and researched here but i wasnt foundable I have a question about swaping the position of 4 lists in 1 one whole list

a={{{1,2,3,4},{1,2,4,2}},{{1,4,8,1},{1,9,8,2}}}

Now i want to change the second and third position! So i need something like

ares={{{1,3,2,4},{1,4,2,2}},{{1,8,4,1},{1,8,9,2}}}

Thank you very much for your support

$\endgroup$

marked as duplicate by Mr.Wizard list-manipulation Aug 24 '17 at 19:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7
$\begingroup$
list = {{{1, 2, 3, 4}, {1, 2, 4, 2}}, {{1, 4, 8, 1}, {1, 9, 8, 2}}}

ares = list /. {a_, b_, c_, d_} :> {a, c, b, d}

{{{1, 3, 2, 4}, {1, 4, 2, 2}}, {{1, 8, 4, 1}, {1, 8, 9, 2}}}

Or

ares = Apply[{#1, #3, #2, #4}&, list, {2}];
$\endgroup$
12
$\begingroup$
a = {{{1, 2, 3, 4}, {1, 2, 4, 2}}, {{1, 4, 8, 1}, {1, 9, 8, 2}}};
ares = a[[All, All, {1, 3, 2, 4}]]

{{{1, 3, 2, 4}, {1, 4, 2, 2}}, {{1, 8, 4, 1}, {1, 8, 9, 2}}}

$\endgroup$

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