2
$\begingroup$

How do I flatten a list of the form

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

to put it in the form

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

required to use ListDensityPlot? Thanks in advance for any help.

$\endgroup$
  • $\begingroup$ You can also use Interpolation and DensityPlot $\endgroup$ – cvgmt Jan 1 at 1:37
  • $\begingroup$ You can do it with ReplaceAll. Like so: data /. {{a_, b_}, c_} -> {a, b, c} $\endgroup$ – m_goldberg Jan 1 at 1:59
3
$\begingroup$
Flatten[#] & /@ {{{1, 2}, 3}, {{4, 5}, 6}, {{7, 8}, 9}}

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

The above Flattens each sublist.

Mr. Hanlon makes the good point that:

Flatten /@ {{{1, 2}, 3}, {{4, 5}, 6}, {{7, 8}, 9}}

works as well.

$\endgroup$
  • 2
    $\begingroup$ Since single-argument functions do not need an explicit argument when mapped, Flatten /@ list also works. $\endgroup$ – Bob Hanlon Dec 31 '20 at 18:00

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