1
$\begingroup$

I have an output like this:

out = {{{x1, y1, z1}, {a1, b1, c1}}, {{x2, y2, z2}, {a2, b2, c2}}, {{x3, y3, z3}, {a3, b3, c3}}};

Now want to save this output in two different variables A and B so that I can use it as independent variable

A = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}

and

B = {{a1, b1, c1}, {a2, b2, c2}, {a3, b3, c3}}

How can I do that?

$\endgroup$
  • 2
    $\begingroup$ A = out[[All, 1]] and B = out[[All, 2]]. $\endgroup$ – corey979 Apr 26 '18 at 20:00
2
$\begingroup$
{A, B} = Transpose[{{{x1, y1, z1}, {a1, b1, c1}}, {{x2, y2, z2}, {a2, 
    b2, c2}}, {{x3, y3, z3}, {a3, b3, c3}}}]

Transpose flips the list, and then you can directly assign A and B to the two columns in the result. Transpose is very powerful for this sort of manipulation, and it can transpose between several different levels of a list, so I'd recommend checking the documentation on it for more details.

$\endgroup$
  • $\begingroup$ Thank you very much for the help and kind suggestions. $\endgroup$ – Bikash Apr 26 '18 at 15:23
  • $\begingroup$ @Bikash If this answers your question sufficiently, please consider accepting the answer. $\endgroup$ – eyorble Apr 27 '18 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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