2
$\begingroup$

I have a data list like below:

data = {{{-13.236, 25.903, 13.937}, {-22.42, -10.451, 24.981}, 
         {-2.877, -11.507, 33.117}, {6.905, -4.385, 39.751}, 
         {1.81, -22.179, 21.071}, {-16.151, -12.976, 25.321}}}

From here I want to make

data = {{-13.236, 25.903, 13.937}, {-22.42, -10.451, 24.981}, 
        {-2.877, -11.507, 33.117}, {6.905, -4.385, 39.751}, 
        {1.81, -22.179, 21.071}, {-16.151, -12.976, 25.321}}

How to do that?

$\endgroup$
5
$\begingroup$

Use First[data] or data[[1]] or Sequence @@ data.

Update: Additional Identity @@ data

| improve this answer | |
$\endgroup$
  • $\begingroup$ @Pavel..Thanks, First[data] or data[[1]] works fine but getting problem with Sequence @@ data...any comments? Maybe Sequence @@@ data works. $\endgroup$ – Bikash Jun 9 '18 at 14:03
  • $\begingroup$ Of course, Sequence@@data will be useful only in list context, i.e. {a,Sequence@@data, b} that replace data list by sequence of elements. Header Sequence remains on upper level (but First@data == Sequence @@ data). Sequence@@@data replace each inner List in outer List (remove {} of next level) that is not the same. $\endgroup$ – Pavel Smirnov Jun 9 '18 at 15:26
1
$\begingroup$

Another option is Flatten, which is specifically designed for this problem. Thus:

Flatten[data,1]

{{-13.236, 25.903, 13.937}, {-22.42, -10.451, 24.981}, {-2.877, -11.507, 33.117}, {6.905, -4.385, 39.751}, {1.81, -22.179, 21.071}, {-16.151, -12.976, 25.321}}

and:

Flatten[data]

{-13.236, 25.903, 13.937, -22.42, -10.451, 24.981, -2.877, -11.507, 33.117, 6.905, -4.385, 39.751, 1.81, -22.179, 21.071, -16.151, -12.976, 25.321}

| improve this answer | |
$\endgroup$

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