mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
61 lines
1.8 KiB
Markdown
61 lines
1.8 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-mapslices">Function mapSlices <a href="#function-mapslices" title="Permalink">#</a></h1>
|
|
|
|
Apply a function that maps an array to a scalar
|
|
along a given axis of a matrix or array.
|
|
Returns a new matrix or array with one less dimension than the input.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.mapSlices(A, dim, callback)
|
|
```
|
|
|
|
<h3 id="where">Where <a href="#where" title="Permalink">#</a></h3>
|
|
|
|
- `dim: number` is a zero-based dimension over which to concatenate the matrices.
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`array` | Array | Matrix | The input Matrix
|
|
`dim` | number | The dimension along which the callback is applied
|
|
`callback` | Function | The callback function that is applied. This Function should take an array or 1-d matrix as an input and return a number.
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Array | Matrix | res The residual matrix with the function mapped on the slices over some dimension.
|
|
|
|
|
|
<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
|
|
const A = [[1, 2], [3, 4]]
|
|
const sum = math.sum
|
|
|
|
math.mapSlices(A, 0, sum) // returns [4, 6]
|
|
math.mapSlices(A, 1, sum) // returns [3, 7]
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[map](map.html),
|
|
[filter](filter.html),
|
|
[forEach](forEach.html)
|