2018-06-16 15:39:07 +02:00

55 lines
1.4 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-reshape">Function reshape <a href="#function-reshape" title="Permalink">#</a></h1>
Reshape a multi dimensional array to fit the specified dimensions
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.reshape(x, sizes)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix &#124; * | Matrix to be reshaped
`sizes` | number[] | One dimensional array with integral sizes for each dimension
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
* &#124; Array &#124; Matrix | A reshaped clone of matrix `x`
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
math.reshape([1, 2, 3, 4, 5, 6], [2, 3])
// returns Array [[1, 2, 3], [4, 5, 6]]
math.reshape([[1, 2], [3, 4]], [1, 4])
// returns Array [[1, 2, 3, 4]]
math.reshape([[1, 2], [3, 4]], [4])
// returns Array [1, 2, 3, 4]
const x = math.matrix([1, 2, 3, 4, 5, 6, 7, 8])
math.reshape(x, [2, 2, 2])
// returns Matrix [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[size](size.html),
[squeeze](squeeze.html),
[resize](resize.html)