3
$\begingroup$

I have a long vector array in the following format:

{{{{x1,y1,z1,{a,b,c}},{x1,y1,z2,{d,e,f}},...},{{x1,y2,z1,{g,h,i}},{x1,y2,z2,   
{g,h,i}},...},...},{{{x2,y1,z1,{j,k,l}},{x2,y2,z1,{m,n,o}},...},{{x2,y2,z1,   
{p,r,s}},{x1,y2,z2,{t,u,v}},...},...}}

I need to add brackets to the first three terms {xi,yi,zi} of every {xi,yi,zi,{a,b,c}}, but I couldn't figure it out myself using

Partition

Thank you.

$\endgroup$
  • 2
    $\begingroup$ ArrayReshape[t, Join[Most@Dimensions@t, {2, 3}]]] where t is the target... $\endgroup$ – ciao Jun 13 '15 at 5:17
  • 6
    $\begingroup$ list /. {x1_,y1_,z1_,{a_,b_,c_}}:>{{x1,y1,z1},{a,b,c}} $\endgroup$ – Sjoerd C. de Vries Jun 13 '15 at 6:58
  • 1
    $\begingroup$ @SjoerdC.deVries: Yes, I took OP "long" as implying performance mattered, invoking pattern matcher costs 50-100% performance hit vs reshape... +1 on cmnt though! $\endgroup$ – ciao Jun 13 '15 at 21:00
  • $\begingroup$ @ciao Could you post that as an answer or vote to close?. Otherwise this will be kept on the unanswered queue $\endgroup$ – Dr. belisarius Oct 8 '15 at 20:09
  • $\begingroup$ @belisariusisforth done $\endgroup$ – ciao Oct 8 '15 at 22:22
2
$\begingroup$

The comment as answer, per request:

ArrayReshape[t, Join[Most@Dimensions@t, {2, 3}]]]

where t is the target.

$\endgroup$

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.