next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: flatten

flatten -- flatten a nested list or a matrix

Synopsis

Description

If x is a list, then flatten x effectively removes the braces surrounding any elements of x that happen to be lists.

i1 : flatten {{2,3,4}, {{5}, 6}, 7}

o1 = {2, 3, 4, {5}, 6, 7}

o1 : List

If x is a matrix, then flatten x puts the elements of x in a single row, ordered by column. If x is an m×n matrix, then flatten x is a 1×mn matrix.

i2 : R = ZZ/101[a,b,c];
i3 : m = matrix {{2, a},{b^2, 23},{c, c^3}}

o3 = | 2  a  |
     | b2 23 |
     | c  c3 |

             3       2
o3 : Matrix R  <--- R
i4 : flatten m

o4 = | 2 b2 c a 23 c3 |

             1       6
o4 : Matrix R  <--- R

Caveat

The matrix produced by flatten m is not the same as the matrix given by unnesting the list used to define the matrix.

See also

Ways to use flatten :