1 |
|
2 |
|
3 | # Function resize
|
4 |
|
5 | Resize a matrix
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.resize(x, size)
|
12 | math.resize(x, size, defaultValue)
|
13 | ```
|
14 |
|
15 | ### Parameters
|
16 |
|
17 | Parameter | Type | Description
|
18 | --------- | ---- | -----------
|
19 | `x` | Array | Matrix | * | Matrix to be resized
|
20 | `size` | Array | Matrix | One dimensional array with numbers
|
21 | `defaultValue` | number | string | Zero by default, except in case of a string, in that case defaultValue = ' ' Default value: 0.
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | * | Array | Matrix | A resized clone of matrix `x`
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.resize([1, 2, 3, 4, 5], [3]) // returns Array [1, 2, 3]
|
34 | math.resize([1, 2, 3], [5], 0) // returns Array [1, 2, 3, 0, 0]
|
35 | math.resize(2, [2, 3], 0) // returns Matrix [[2, 0, 0], [0, 0, 0]]
|
36 | math.resize("hello", [8], "!") // returns string 'hello!!!'
|
37 | ```
|
38 |
|
39 |
|
40 | ## See also
|
41 |
|
42 | [size](size.md),
|
43 | [squeeze](squeeze.md),
|
44 | [subset](subset.md),
|
45 | [reshape](reshape.md)
|