mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
* enable sum function to take an argument of dimension for a matrix fulfilling issue #1244 * added sum along a dimension to the unit test coverage for sum * added information about sum along a dimension to the markdown * fixed typo in error message * made formatting chagnes for linter * add sum to transformed functions
1.1 KiB
1.1 KiB
Function sum
Compute the sum of a matrix or a list with values.
In case of a (multi dimensional) array or matrix, the sum of all
elements will be calculated. When dim is provided, the sum over the selected
dimension will be calculated. Parameter dim is zero-based.
Syntax
math.sum(a, b, c, ...)
math.sum(A)
math.sum(A, dim)
Parameters
| Parameter | Type | Description |
|---|---|---|
args |
... * | A single matrix or or multiple scalar values |
Returns
| Type | Description |
|---|
- | The sum of all values
Examples
math.sum(2, 1, 4, 3) // returns 10
math.sum([2, 1, 4, 3]) // returns 10
math.sum([[2, 5], [4, 3], [1, 7]]) // returns 22
math.sum([[2, 5], [4, 3], [1, 7]], 0) // returns [7, 15]
math.sum([[2, 5], [4, 3], [1, 7]], 1) // returns [7, 7, 8]