函数 squeeze #
压缩矩阵,移除矩阵的内部和外部单例维度。
Syntax #
math.squeeze(x)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
矩阵 | 数组 | 要压缩的矩阵 |
Returns #
| Type | Description |
|---|---|
| 矩阵 | 数组 | 压缩后的矩阵 |
Throws #
Type | Description —- | ———–
Examples #
math.squeeze([3]) // returns 3
math.squeeze([[3]]) // returns 3
const A = math.zeros(3, 1) // returns [[0], [0], [0]] (size 3x1)
math.squeeze(A) // returns [0, 0, 0] (size 3)
const B = math.zeros(1, 3) // returns [[0, 0, 0]] (size 1x3)
math.squeeze(B) // returns [0, 0, 0] (size 3)
// only inner and outer dimensions are removed
const C = math.zeros(2, 1, 3) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)
math.squeeze(C) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)