mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
58 lines
1.6 KiB
Markdown
58 lines
1.6 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
|
|
|
<h1 id="function-squeeze">Function squeeze <a href="#function-squeeze" title="Permalink">#</a></h1>
|
|
|
|
Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.squeeze(x)
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`x` | Matrix | Array | Matrix to be squeezed
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Matrix | Array | Squeezed matrix
|
|
|
|
|
|
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
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)
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[subset](subset.html)
|