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$
  • 2
    $\begingroup$ Flatten[{{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}}}, {{1}, {2, 3}}]. (Pretty sure this is a dupe...) $\endgroup$ – J. M. will be back soon Jul 31 '17 at 16:34
  • $\begingroup$ Or perhaps even Flatten /@ {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}}} $\endgroup$ – user6014 Jul 31 '17 at 16:40
  • 2
    $\begingroup$ {{{1}, {2}, {3}, {4}, {5}, {6}}, {{7}, {8}, {9}, {10}}}[[All, All, 1]] $\endgroup$ – m_goldberg Jul 31 '17 at 17:20
  • 1
    $\begingroup$ With white-out? $\endgroup$ – Daniel Lichtblau Jul 31 '17 at 18:29
5
$\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$
  • $\begingroup$ I see that you have adopted my solution since this was last asked. ;^) $\endgroup$ – Mr.Wizard Jul 31 '17 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 Jul 31 '17 at 23:59
  • $\begingroup$ I am sincerely flattered. Also I strongly suspect your memory works better than mine, age notwithstanding. $\endgroup$ – Mr.Wizard Aug 1 '17 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
    $\begingroup$ Isn't this the same answer as eldo's above? $\endgroup$ – MarcoB Jul 31 '17 at 19:27

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