Skip to main content
7 of 9
added 5 characters in body
Conor Cosnett
  • 7.9k
  • 1
  • 26
  • 47

wrap the matrix rows with the the Flatten function

M = {{{1}, {2}, {3}, {4}}, {{5}, {6}, {7}, {8}}} 

enter image description here

To save time you can wrap your whole matrix using: Map[Flatten, <yourmatrix> ]

Map[Flatten,{{{1}, {2}, {3}, {4}}, {{5}, {6}, {7}, {8}}}] 

the outermost list contains two elements (the rows). the Map function wraps these elements with the Flatten function

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

In Mathematica this is known as "nested" Lists. Flatten removes all wrappings of the List function until only one remains

To understand what the Map function does: Below is the "manual" approach without the Map function.

{ Flatten[{{1}, {2}, {3}, {4}}], Flatten[{{5}, {6}, {7}, {7}}] } 

As you are talking to the Mathematica kernel you don't have to waste time writing things in long hand to make them readable (like you would for a slow-to-understand human reader of an essay or your future self reading your code).

hence Map[Flatten, Matrix] has the terse shorthand form Flatten /@ matrix

mentioned by @garej , @jjc385 and @Mr.Wizard below

Conor Cosnett
  • 7.9k
  • 1
  • 26
  • 47