1 |
|
2 |
|
3 | # Function reshape
|
4 |
|
5 | Reshape a multi dimensional array to fit the specified dimensions
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.reshape(x, sizes)
|
12 | ```
|
13 |
|
14 | ### Parameters
|
15 |
|
16 | Parameter | Type | Description
|
17 | --------- | ---- | -----------
|
18 | `x` | Array | Matrix | * | Matrix to be reshaped
|
19 | `sizes` | number[] | One dimensional array with integral sizes for each dimension. One -1 is allowed as wildcard, which calculates this dimension automatically.
|
20 |
|
21 | ### Returns
|
22 |
|
23 | Type | Description
|
24 | ---- | -----------
|
25 | * | Array | Matrix | A reshaped clone of matrix `x`
|
26 |
|
27 |
|
28 | ## Examples
|
29 |
|
30 | ```js
|
31 | math.reshape([1, 2, 3, 4, 5, 6], [2, 3])
|
32 | // returns Array [[1, 2, 3], [4, 5, 6]]
|
33 |
|
34 | math.reshape([[1, 2], [3, 4]], [1, 4])
|
35 | // returns Array [[1, 2, 3, 4]]
|
36 |
|
37 | math.reshape([[1, 2], [3, 4]], [4])
|
38 | // returns Array [1, 2, 3, 4]
|
39 |
|
40 | const x = math.matrix([1, 2, 3, 4, 5, 6, 7, 8])
|
41 | math.reshape(x, [2, 2, 2])
|
42 | // returns Matrix [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
|
43 |
|
44 | math.reshape([1, 2, 3, 4], [-1, 2])
|
45 | // returns Matrix [[1, 2], [3, 4]]
|
46 | ```
|
47 |
|
48 |
|
49 | ## See also
|
50 |
|
51 | [size](size.md),
|
52 | [squeeze](squeeze.md),
|
53 | [resize](resize.md)
|