# flatten() Function & Examples

Use the flatten() matrix function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## flatten

#### flatten(x)

Try it yourself:

```calculio
a = [1, 2, 3; 4, 5, 6]
size(a)
b = flatten(a)
size(b)
```

[concat](https://calcul.io/function/concat/index.md)

[resize](https://calcul.io/function/resize/index.md)

[size](https://calcul.io/function/size/index.md)

[squeeze](https://calcul.io/function/squeeze/index.md)

---

## 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](https://calcul.io/function/concat/index.md) when joining compatible blocks is the main intention, and [reshape](https://calcul.io/function/reshape/index.md) 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](https://calcul.io/function/size/index.md) first if those dimensions carry meaning. After flattening, [count](https://calcul.io/function/count/index.md) reports total entries and [sum](https://calcul.io/function/sum/index.md) can aggregate numeric values. Do not flatten merely to hide incompatible shapes in matrix algebra.

[All functions](https://calcul.io/functions/index.md)
