UNPKG

1.04 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function reshape
4
5Reshape a multi dimensional array to fit the specified dimensions
6
7
8## Syntax
9
10```js
11math.reshape(x, sizes)
12```
13
14### Parameters
15
16Parameter | Type | Description
17--------- | ---- | -----------
18`x` | Array &#124; Matrix &#124; * | Matrix to be reshaped
19`sizes` | number[] | One dimensional array with integral sizes for each dimension
20
21### Returns
22
23Type | Description
24---- | -----------
25* &#124; Array &#124; Matrix | A reshaped clone of matrix `x`
26
27
28## Examples
29
30```js
31math.reshape([1, 2, 3, 4, 5, 6], [2, 3])
32// returns Array [[1, 2, 3], [4, 5, 6]]
33
34math.reshape([[1, 2], [3, 4]], [1, 4])
35// returns Array [[1, 2, 3, 4]]
36
37math.reshape([[1, 2], [3, 4]], [4])
38// returns Array [1, 2, 3, 4]
39
40const x = math.matrix([1, 2, 3, 4, 5, 6, 7, 8])
41math.reshape(x, [2, 2, 2])
42// returns Matrix [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
43```
44
45
46## See also
47
48[size](size.md),
49[squeeze](squeeze.md),
50[resize](resize.md)