flatten

flatten(x)

Try it yourself:


Flatten nested collections

flatten(x) removes nesting from an array or matrix-like collection and returns its values in a one-dimensional sequence. It is helpful when data arrives in blocks but a later calculation needs one list.

Example

Flattening [[1, 2], [3, 4]] produces [1, 2, 3, 4]. Use concat when joining compatible blocks is the main intention, and reshape when you need to retain every value but establish a new explicit matrix shape.

Structure matters

Flattening discards row and column boundaries, so check size first if those dimensions carry meaning. After flattening, count reports total entries and sum can aggregate numeric values. Do not flatten merely to hide incompatible shapes in matrix algebra.

All functions