1 |
|
2 |
|
3 | # Function squeeze
|
4 |
|
5 | Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.squeeze(x)
|
12 | ```
|
13 |
|
14 | ### Parameters
|
15 |
|
16 | Parameter | Type | Description
|
17 | --------- | ---- | -----------
|
18 | `x` | Matrix | Array | Matrix to be squeezed
|
19 |
|
20 | ### Returns
|
21 |
|
22 | Type | Description
|
23 | ---- | -----------
|
24 | Matrix | Array | Squeezed matrix
|
25 |
|
26 |
|
27 | ## Examples
|
28 |
|
29 | ```js
|
30 | math.squeeze([3]) // returns 3
|
31 | math.squeeze([[3]]) // returns 3
|
32 |
|
33 | const A = math.zeros(3, 1) // returns [[0], [0], [0]] (size 3x1)
|
34 | math.squeeze(A) // returns [0, 0, 0] (size 3)
|
35 |
|
36 | const B = math.zeros(1, 3) // returns [[0, 0, 0]] (size 1x3)
|
37 | math.squeeze(B) // returns [0, 0, 0] (size 3)
|
38 |
|
39 | // only inner and outer dimensions are removed
|
40 | const C = math.zeros(2, 1, 3) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)
|
41 | math.squeeze(C) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)
|
42 | ```
|
43 |
|
44 |
|
45 | ## See also
|
46 |
|
47 | [subset](subset.md)
|