reshape

reshape(x, sizes)

Try it yourself:

See also:

reshape(): Changing Array Dimensions

reshape() changes an array or matrix’s dimensions without changing its total number of entries. It is useful for preparing data for a matrix operation or converting between flat and grid-like layouts.

Preserve element count

The requested dimensions must contain exactly the same number of values as the input. Check sizes with size() before reshaping. reshape does not transpose data; use transpose() when rows and columns should swap.

Be explicit about ordering, especially when exchanging data with other systems. Use flatten() to make a one-dimensional view, and resize() only when adding or removing entries is intended.

Try Reshape 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