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.

Try Flatten in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions