--- layout: default ---

Function sum #

Compute the sum of a matrix or a list with values. In case of a multidimensional array or matrix, the sum of all elements will be calculated.

Syntax #

```js math.sum(a, b, c, ...) math.sum(A) math.sum(A, dimension) ```

Parameters #

Parameter | Type | Description --------- | ---- | ----------- `args` | ... * | A single matrix or multiple scalar values

Returns #

Type | Description ---- | ----------- * | The sum of all values

Throws #

Type | Description ---- | -----------

Examples #

```js 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 ```

See also #

[mean](mean.html), [median](median.html), [min](min.html), [max](max.html), [prod](prod.html), [std](std.html), [variance](variance.html), [cumsum](cumsum.html)