UNPKG

1.19 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function apply
4
5Apply a function that maps an array to a scalar
6along a given axis of a matrix or array.
7Returns a new matrix or array with one less dimension than the input.
8
9
10## Syntax
11
12```js
13math.apply(A, dim, callback)
14```
15
16### Where
17
18- `dim: number` is a zero-based dimension over which to concatenate the matrices.
19
20### Parameters
21
22Parameter | Type | Description
23--------- | ---- | -----------
24`array` | Array &#124; Matrix | The input Matrix
25`dim` | number | The dimension along which the callback is applied
26`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.
27
28### Returns
29
30Type | Description
31---- | -----------
32Array &#124; Matrix | res The residual matrix with the function applied over some dimension.
33
34
35## Examples
36
37```js
38const A = [[1, 2], [3, 4]]
39const sum = math.sum
40
41math.apply(A, 0, sum) // returns [4, 6]
42math.apply(A, 1, sum) // returns [3, 7]
43```
44
45
46## See also
47
48[map](map.md),
49[filter](filter.md),
50[forEach](forEach.md)