bnlcas e45c8805b3 Add axis for sum request 1244 (#1310)
* 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
2018-12-09 13:09:36 +01:00

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]

See also

mean, median, min, max, prod, std, var