4
$\begingroup$

I have a list/array like so:

{{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}, ... }}

I want to remove the curly brackets around each element (so I can use ListDensityPlot) so that I have:

{{1, 2, 3, 4, 5, 6}, {7, 8, 9, ...}}

$\endgroup$
4
  • 2
    $\begingroup$ Flatten[{{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}}}, {{1}, {2, 3}}]. (Pretty sure this is a dupe...) $\endgroup$ Commented Jul 31, 2017 at 16:34
  • $\begingroup$ Or perhaps even Flatten /@ {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}}} $\endgroup$
    – ktm
    Commented Jul 31, 2017 at 16:40
  • 2
    $\begingroup$ {{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}}}[[All, All, 1]] $\endgroup$
    – m_goldberg
    Commented Jul 31, 2017 at 17:20
  • 1
    $\begingroup$ With white-out? $\endgroup$ Commented Jul 31, 2017 at 18:29

3 Answers 3

7
$\begingroup$
list = {{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}}};

Flatten /@ list

{{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10}}

Or use the operator form

Map[Flatten] @ list
$\endgroup$
4
$\begingroup$

Just to put my comment on record, I propose

{{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}}}[[All, All, 1]]

which gives

{{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10}}

$\endgroup$
3
  • $\begingroup$ I see that you have adopted my solution since this was last asked. ;^) $\endgroup$
    – Mr.Wizard
    Commented Jul 31, 2017 at 22:19
  • 1
    $\begingroup$ @Mr.Wizard. Why not? Your methods are often the best, and I can still learn even at my advanced age. $\endgroup$
    – m_goldberg
    Commented Jul 31, 2017 at 23:59
  • $\begingroup$ I am sincerely flattered. Also I strongly suspect your memory works better than mine, age notwithstanding. $\endgroup$
    – Mr.Wizard
    Commented Aug 1, 2017 at 9:46
1
$\begingroup$

Given your list as:

list = {{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}}};

Use Flatten to remove the inner brackets.

Flatten /@ list

Which gives:

{{1, 2, 3, 4, 5, 6}, {7, 8, 9, 10}}
$\endgroup$
1
  • 1
    $\begingroup$ Isn't this the same answer as eldo's above? $\endgroup$
    – MarcoB
    Commented Jul 31, 2017 at 19:27

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